summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/lineedit.c40
-rw-r--r--libbb/read_key.c11
2 files changed, 48 insertions, 3 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:
diff --git a/libbb/read_key.c b/libbb/read_key.c
index 5dcd19c..8d72d2a 100644
--- a/libbb/read_key.c
+++ b/libbb/read_key.c
@@ -40,13 +40,14 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout)
'[','C' |0x80,KEYCODE_RIGHT ,
'[','D' |0x80,KEYCODE_LEFT ,
/* ESC [ 1 ; 2 x, where x = A/B/C/D: Shift-<arrow> */
- /* ESC [ 1 ; 3 x, where x = A/B/C/D: Alt-<arrow> */
+ /* ESC [ 1 ; 3 x, where x = A/B/C/D: Alt-<arrow> - implemented below */
/* ESC [ 1 ; 4 x, where x = A/B/C/D: Alt-Shift-<arrow> */
/* ESC [ 1 ; 5 x, where x = A/B/C/D: Ctrl-<arrow> - implemented below */
/* ESC [ 1 ; 6 x, where x = A/B/C/D: Ctrl-Shift-<arrow> */
'[','H' |0x80,KEYCODE_HOME , /* xterm */
- /* [ESC] ESC [ [2] H - [Alt-][Shift-]Home */
'[','F' |0x80,KEYCODE_END , /* xterm */
+ /* [ESC] ESC [ [2] H - [Alt-][Shift-]Home (End similarly?) */
+ /* '[','Z' |0x80,KEYCODE_SHIFT_TAB, */
'[','1','~' |0x80,KEYCODE_HOME , /* vt100? linux vt? or what? */
'[','2','~' |0x80,KEYCODE_INSERT ,
/* ESC [ 2 ; 3 ~ - Alt-Insert */
@@ -86,8 +87,12 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout)
/* '[','1',';','5','B' |0x80,KEYCODE_CTRL_DOWN , - unused */
'[','1',';','5','C' |0x80,KEYCODE_CTRL_RIGHT,
'[','1',';','5','D' |0x80,KEYCODE_CTRL_LEFT ,
+ /* '[','1',';','3','A' |0x80,KEYCODE_ALT_UP , - unused */
+ /* '[','1',';','3','B' |0x80,KEYCODE_ALT_DOWN , - unused */
+ '[','1',';','3','C' |0x80,KEYCODE_ALT_RIGHT,
+ '[','1',';','3','D' |0x80,KEYCODE_ALT_LEFT ,
+ /* '[','3',';','3','~' |0x80,KEYCODE_ALT_DELETE, - unused */
0
- /* ESC [ Z - Shift-Tab */
};
pfd.fd = fd;