diff options
author | Denys Vlasenko | 2011-11-03 13:28:22 +0100 |
---|---|---|
committer | Denys Vlasenko | 2011-11-03 13:28:22 +0100 |
commit | 9ce09bc9cb7743f87eb3e536c81d8c303e12bc81 (patch) | |
tree | ad65a2f47136af7a730b630c4e08532c02ff0fb6 /libbb/lineedit.c | |
parent | 45cdf166dccb4981004bae822f52e48df05aab91 (diff) | |
download | busybox-9ce09bc9cb7743f87eb3e536c81d8c303e12bc81.zip busybox-9ce09bc9cb7743f87eb3e536c81d8c303e12bc81.tar.gz |
lineedit: add support for M-b, M-f, M-d, M-Backspace
function old new delta
ctrl_left - 96 +96
ctrl_right - 76 +76
static.esccmds 81 93 +12
read_line_input 3876 3885 +9
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/0 up/down: 193/0) Total: 193 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r-- | libbb/lineedit.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 603bbfc..0d23288 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -2504,6 +2504,44 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman vi_cmdmode = 1; input_backward(1); } + /* Handle a few ESC-<key> combinations the same way + * standard readline bindings (IOW: bash) do. + * Often, Alt-<key> generates ESC-<key>. + */ + ic = lineedit_read_key(read_key_buffer, timeout); + switch (ic) { + //case KEYCODE_LEFT: - bash doesn't do this + case 'b': + ctrl_left(); + break; + //case KEYCODE_RIGHT: - bash doesn't do this + case 'f': + ctrl_right(); + break; + //case KEYCODE_DELETE: - bash doesn't do this + case 'd': /* Alt-D */ + { + /* Delete word forward */ + int nc, sc = cursor; + ctrl_right(); + nc = cursor; + input_backward(cursor - sc); + while (--nc >= cursor) + input_delete(1); + break; + } + case '\b': /* Alt-Backspace(?) */ + case '\x7f': /* Alt-Backspace(?) */ + //case 'w': - bash doesn't do this + { + /* Delete word backward */ + int sc = cursor; + ctrl_left(); + while (sc-- > cursor) + input_delete(1); + break; + } + } break; #endif /* FEATURE_COMMAND_EDITING_VI */ @@ -2532,9 +2570,11 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman input_backward(1); break; case KEYCODE_CTRL_LEFT: + case KEYCODE_ALT_LEFT: /* bash doesn't do it */ ctrl_left(); break; case KEYCODE_CTRL_RIGHT: + case KEYCODE_ALT_RIGHT: /* bash doesn't do it */ ctrl_right(); break; case KEYCODE_HOME: |