diff options
author | nicm <nicm> | 2016-10-12 13:03:27 +0000 |
---|---|---|
committer | nicm <nicm> | 2016-10-12 13:03:27 +0000 |
commit | 68bebe1fb7dfe5d152a2734c5bd572b1db641a4c (patch) | |
tree | ebd451ee92e938399563bb994b572639af3e75cd /status.c | |
parent | 22a8afee9e8dcbe45a371ca72af0169b7c94eac5 (diff) |
The repeat prompt in both emacs and vi (and the old one in tmux) doesn't
support line editing and instead executes a command as soon as a
non-number key is pressed. Add a -N flag to command-prompt for the same
in copy mode. Reported by Theo Buehler.
Diffstat (limited to 'status.c')
-rw-r--r-- | status.c | 76 |
1 files changed, 45 insertions, 31 deletions
@@ -855,7 +855,7 @@ status_prompt_space(const struct utf8_data *ud) } /* Handle keys in prompt. */ -void +int status_prompt_key(struct client *c, key_code key) { struct options *oo = c->session->options; @@ -867,6 +867,17 @@ status_prompt_key(struct client *c, key_code key) struct utf8_data tmp, *first, *last, *ud; size = utf8_strlen(c->prompt_buffer); + + if (c->prompt_flags & PROMPT_NUMERIC) { + if (key >= '0' && key <= '9') + goto append_key; + s = utf8_tocstr(c->prompt_buffer); + c->prompt_callbackfn(c->prompt_data, s); + status_prompt_clear(c); + free(s); + return (1); + } + switch (mode_key_lookup(&c->prompt_mdata, key)) { case MODEKEYEDIT_CURSORLEFT: if (c->prompt_index > 0) { @@ -1185,41 +1196,44 @@ status_prompt_key(struct client *c, key_code key) status_prompt_clear(c); break; case MODEKEY_OTHER: - if (key <= 0x1f || key >= KEYC_BASE) - break; - if (utf8_split(key, &tmp) != UTF8_DONE) - break; + break; + default: + return (0); + } - c->prompt_buffer = xreallocarray(c->prompt_buffer, size + 2, - sizeof *c->prompt_buffer); +append_key: + if (key <= 0x1f || key >= KEYC_BASE) + return (0); + if (utf8_split(key, &tmp) != UTF8_DONE) + return (0); - if (c->prompt_index == size) { - utf8_copy(&c->prompt_buffer[c->prompt_index], &tmp); - c->prompt_index++; - c->prompt_buffer[c->prompt_index].size = 0; - } else { - memmove(c->prompt_buffer + c->prompt_index + 1, - c->prompt_buffer + c->prompt_index, - (size + 1 - c->prompt_index) * - sizeof *c->prompt_buffer); - utf8_copy(&c->prompt_buffer[c->prompt_index], &tmp); - c->prompt_index++; - } + c->prompt_buffer = xreallocarray(c->prompt_buffer, size + 2, + sizeof *c->prompt_buffer); - if (c->prompt_flags & PROMPT_SINGLE) { - s = utf8_tocstr(c->prompt_buffer); - if (strlen(s) != 1) - status_prompt_clear(c); - else if (c->prompt_callbackfn(c->prompt_data, s) == 0) - status_prompt_clear(c); - free(s); - } + if (c->prompt_index == size) { + utf8_copy(&c->prompt_buffer[c->prompt_index], &tmp); + c->prompt_index++; + c->prompt_buffer[c->prompt_index].size = 0; + } else { + memmove(c->prompt_buffer + c->prompt_index + 1, + c->prompt_buffer + c->prompt_index, + (size + 1 - c->prompt_index) * + sizeof *c->prompt_buffer); + utf8_copy(&c->prompt_buffer[c->prompt_index], &tmp); + c->prompt_index++; + } - c->flags |= CLIENT_STATUS; - break; - default: - break; + if (c->prompt_flags & PROMPT_SINGLE) { + s = utf8_tocstr(c->prompt_buffer); + if (strlen(s) != 1) + status_prompt_clear(c); + else if (c->prompt_callbackfn(c->prompt_data, s) == 0) + status_prompt_clear(c); + free(s); } + + c->flags |= CLIENT_STATUS; + return (0); } /* Get previous line from the history. */ |