version 1.19, 2009/07/27 18:51:46 |
version 1.20, 2009/07/27 19:29:35 |
|
|
int (*callbackfn)(void *, const char *), void (*freefn)(void *), |
int (*callbackfn)(void *, const char *), void (*freefn)(void *), |
void *data, int flags) |
void *data, int flags) |
{ |
{ |
|
int keys; |
|
|
status_message_clear(c); |
status_message_clear(c); |
status_prompt_clear(c); |
status_prompt_clear(c); |
|
|
|
|
|
|
c->prompt_flags = flags; |
c->prompt_flags = flags; |
|
|
mode_key_init(&c->prompt_mdata, |
keys = options_get_number(&c->session->options, "status-keys"); |
options_get_number(&c->session->options, "status-keys"), |
if (keys == MODEKEY_EMACS) |
MODEKEY_CANEDIT); |
mode_key_init(&c->prompt_mdata, mode_key_emacs_edit); |
|
else |
|
mode_key_init(&c->prompt_mdata, mode_key_vi_edit); |
|
|
c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE); |
c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE); |
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
|
|
|
|
size = strlen(c->prompt_buffer); |
size = strlen(c->prompt_buffer); |
switch (mode_key_lookup(&c->prompt_mdata, key)) { |
switch (mode_key_lookup(&c->prompt_mdata, key)) { |
case MODEKEYCMD_LEFT: |
case MODEKEYEDIT_CURSORLEFT: |
if (c->prompt_index > 0) { |
if (c->prompt_index > 0) { |
c->prompt_index--; |
c->prompt_index--; |
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
} |
} |
break; |
break; |
case MODEKEYCMD_RIGHT: |
case MODEKEYEDIT_SWITCHMODEAPPEND: |
|
case MODEKEYEDIT_CURSORRIGHT: |
if (c->prompt_index < size) { |
if (c->prompt_index < size) { |
c->prompt_index++; |
c->prompt_index++; |
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
} |
} |
break; |
break; |
case MODEKEYCMD_STARTOFLINE: |
case MODEKEYEDIT_STARTOFLINE: |
case MODEKEYCMD_BACKTOINDENTATION: |
|
if (c->prompt_index != 0) { |
if (c->prompt_index != 0) { |
c->prompt_index = 0; |
c->prompt_index = 0; |
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
} |
} |
break; |
break; |
case MODEKEYCMD_ENDOFLINE: |
case MODEKEYEDIT_ENDOFLINE: |
if (c->prompt_index != size) { |
if (c->prompt_index != size) { |
c->prompt_index = size; |
c->prompt_index = size; |
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
} |
} |
break; |
break; |
case MODEKEYCMD_COMPLETE: |
case MODEKEYEDIT_COMPLETE: |
if (*c->prompt_buffer == '\0') |
if (*c->prompt_buffer == '\0') |
break; |
break; |
|
|
|
|
|
|
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
break; |
break; |
case MODEKEYCMD_BACKSPACE: |
case MODEKEYEDIT_BACKSPACE: |
if (c->prompt_index != 0) { |
if (c->prompt_index != 0) { |
if (c->prompt_index == size) |
if (c->prompt_index == size) |
c->prompt_buffer[--c->prompt_index] = '\0'; |
c->prompt_buffer[--c->prompt_index] = '\0'; |
|
|
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
} |
} |
break; |
break; |
case MODEKEYCMD_DELETE: |
case MODEKEYEDIT_DELETE: |
if (c->prompt_index != size) { |
if (c->prompt_index != size) { |
memmove(c->prompt_buffer + c->prompt_index, |
memmove(c->prompt_buffer + c->prompt_index, |
c->prompt_buffer + c->prompt_index + 1, |
c->prompt_buffer + c->prompt_index + 1, |
|
|
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
} |
} |
break; |
break; |
case MODEKEYCMD_DELETETOENDOFLINE: |
case MODEKEYEDIT_DELETETOENDOFLINE: |
if (c->prompt_index < size) { |
if (c->prompt_index < size) { |
c->prompt_buffer[c->prompt_index] = '\0'; |
c->prompt_buffer[c->prompt_index] = '\0'; |
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
} |
} |
break; |
break; |
case MODEKEYCMD_UP: |
case MODEKEYEDIT_HISTORYUP: |
if (server_locked) |
if (server_locked) |
break; |
break; |
|
|
|
|
c->prompt_index = strlen(c->prompt_buffer); |
c->prompt_index = strlen(c->prompt_buffer); |
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
break; |
break; |
case MODEKEYCMD_DOWN: |
case MODEKEYEDIT_HISTORYDOWN: |
if (server_locked) |
if (server_locked) |
break; |
break; |
|
|
|
|
c->prompt_index = strlen(c->prompt_buffer); |
c->prompt_index = strlen(c->prompt_buffer); |
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
break; |
break; |
case MODEKEYCMD_PASTE: |
case MODEKEYEDIT_PASTE: |
if ((pb = paste_get_top(&c->session->buffers)) == NULL) |
if ((pb = paste_get_top(&c->session->buffers)) == NULL) |
break; |
break; |
if ((last = strchr(pb->data, '\n')) == NULL) |
if ((last = strchr(pb->data, '\n')) == NULL) |
|
|
|
|
c->flags |= CLIENT_STATUS; |
c->flags |= CLIENT_STATUS; |
break; |
break; |
case MODEKEYCMD_CHOOSE: |
case MODEKEYEDIT_ENTER: |
if (*c->prompt_buffer != '\0') { |
if (*c->prompt_buffer != '\0') { |
status_prompt_add_history(c); |
status_prompt_add_history(c); |
if (c->prompt_callbackfn( |
if (c->prompt_callbackfn( |
|
|
break; |
break; |
} |
} |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case MODEKEYCMD_QUIT: |
case MODEKEYEDIT_CANCEL: |
if (c->prompt_callbackfn(c->prompt_data, NULL) == 0) |
if (c->prompt_callbackfn(c->prompt_data, NULL) == 0) |
status_prompt_clear(c); |
status_prompt_clear(c); |
break; |
break; |
case MODEKEYCMD_OTHERKEY: |
case MODEKEY_OTHER: |
if (key < 32 || key > 126) |
if (key < 32 || key > 126) |
break; |
break; |
c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + 2); |
c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + 2); |