From fc5f8804ec92389fcc9f3aab1fa0c7777e3f0a56 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 15 Nov 2011 23:34:12 +0000 Subject: Add word movement and editing command for command prompt editing, from Ben Boeckel. --- status.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 3 deletions(-) (limited to 'status.c') diff --git a/status.c b/status.c index 487d3f56..631597da 100644 --- a/status.c +++ b/status.c @@ -973,9 +973,12 @@ status_prompt_redraw(struct client *c) void status_prompt_key(struct client *c, int key) { + struct session *sess = c->session; + struct options *oo = &sess->options; struct paste_buffer *pb; - char *s, *first, *last, word[64], swapc; - const char *histstr; + char *s, *first, *last, word[64], swapc; + const char *histstr; + const char *wsep; u_char ch; size_t size, n, off, idx; @@ -1092,11 +1095,103 @@ status_prompt_key(struct client *c, int key) c->flags |= CLIENT_STATUS; } break; + case MODEKEYEDIT_DELETEWORD: + wsep = options_get_string(oo, "word-separators"); + idx = c->prompt_index; + + /* Find a non-separator. */ + while (idx != 0) { + idx--; + if (!strchr(wsep, c->prompt_buffer[idx])) + break; + } + + /* Find the separator at the beginning of the word. */ + while (idx != 0) { + idx--; + if (strchr(wsep, c->prompt_buffer[idx])) { + /* Go back to the word. */ + idx++; + break; + } + } + + memmove(c->prompt_buffer + idx, + c->prompt_buffer + c->prompt_index, + size + 1 - c->prompt_index); + memset(c->prompt_buffer + size - (c->prompt_index - idx), + '\0', c->prompt_index - idx); + c->prompt_index = idx; + c->flags |= CLIENT_STATUS; + break; + case MODEKEYEDIT_NEXTWORD: + wsep = options_get_string(oo, "word-separators"); + + /* Find a separator. */ + while (c->prompt_index != size) { + c->prompt_index++; + if (strchr(wsep, c->prompt_buffer[c->prompt_index])) + break; + } + + /* Find the word right after the separation. */ + while (c->prompt_index != size) { + c->prompt_index++; + if (!strchr(wsep, c->prompt_buffer[c->prompt_index])) + break; + } + + c->flags |= CLIENT_STATUS; + break; + case MODEKEYEDIT_NEXTWORDEND: + wsep = options_get_string(oo, "word-separators"); + + /* Find a word. */ + while (c->prompt_index != size) { + c->prompt_index++; + if (!strchr(wsep, c->prompt_buffer[c->prompt_index])) + break; + } + + /* Find the separator at the end of the word. */ + while (c->prompt_index != size) { + c->prompt_index++; + if (strchr(wsep, c->prompt_buffer[c->prompt_index])) { + /* Go back to the word. */ + c->prompt_index--; + break; + } + } + + c->flags |= CLIENT_STATUS; + break; + case MODEKEYEDIT_PREVIOUSWORD: + wsep = options_get_string(oo, "word-separators"); + + /* Find a non-separator. */ + while (c->prompt_index != 0) { + c->prompt_index--; + if (!strchr(wsep, c->prompt_buffer[c->prompt_index])) + break; + } + + /* Find the separator at the beginning of the word. */ + while (c->prompt_index != 0) { + c->prompt_index--; + if (strchr(wsep, c->prompt_buffer[c->prompt_index])) { + /* Go back to the word. */ + c->prompt_index++; + break; + } + } + + c->flags |= CLIENT_STATUS; + break; case MODEKEYEDIT_HISTORYUP: histstr = status_prompt_up_history(&c->prompt_hindex); if (histstr == NULL) break; - xfree(c->prompt_buffer); + xfree(c->prompt_buffer); c->prompt_buffer = xstrdup(histstr); c->prompt_index = strlen(c->prompt_buffer); c->flags |= CLIENT_STATUS; -- cgit v1.2.3