diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-11-03 13:28:22 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-11-03 13:28:22 +0100 |
commit | 9ce09bc9cb7743f87eb3e536c81d8c303e12bc81 (patch) | |
tree | ad65a2f47136af7a730b630c4e08532c02ff0fb6 | |
parent | 45cdf166dccb4981004bae822f52e48df05aab91 (diff) | |
download | busybox-w32-9ce09bc9cb7743f87eb3e536c81d8c303e12bc81.tar.gz busybox-w32-9ce09bc9cb7743f87eb3e536c81d8c303e12bc81.tar.bz2 busybox-w32-9ce09bc9cb7743f87eb3e536c81d8c303e12bc81.zip |
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>
-rw-r--r-- | include/libbb.h | 46 | ||||
-rw-r--r-- | libbb/lineedit.c | 40 | ||||
-rw-r--r-- | libbb/read_key.c | 11 |
3 files changed, 77 insertions, 20 deletions
diff --git a/include/libbb.h b/include/libbb.h index 791cdd94e..53224fa35 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1358,25 +1358,37 @@ enum { | |||
1358 | KEYCODE_DELETE = -9, | 1358 | KEYCODE_DELETE = -9, |
1359 | KEYCODE_PAGEUP = -10, | 1359 | KEYCODE_PAGEUP = -10, |
1360 | KEYCODE_PAGEDOWN = -11, | 1360 | KEYCODE_PAGEDOWN = -11, |
1361 | 1361 | // -12 is reserved for Alt/Ctrl/Shift-TAB | |
1362 | KEYCODE_CTRL_UP = KEYCODE_UP & ~0x40, | 1362 | #if 0 |
1363 | KEYCODE_CTRL_DOWN = KEYCODE_DOWN & ~0x40, | 1363 | KEYCODE_FUN1 = -13, |
1364 | KEYCODE_FUN2 = -14, | ||
1365 | KEYCODE_FUN3 = -15, | ||
1366 | KEYCODE_FUN4 = -16, | ||
1367 | KEYCODE_FUN5 = -17, | ||
1368 | KEYCODE_FUN6 = -18, | ||
1369 | KEYCODE_FUN7 = -19, | ||
1370 | KEYCODE_FUN8 = -20, | ||
1371 | KEYCODE_FUN9 = -21, | ||
1372 | KEYCODE_FUN10 = -22, | ||
1373 | KEYCODE_FUN11 = -23, | ||
1374 | KEYCODE_FUN12 = -24, | ||
1375 | #endif | ||
1376 | /* Be sure that last defined value is small enough | ||
1377 | * to not interfere with Alt/Ctrl/Shift bits. | ||
1378 | * So far we do not exceed -31 (0xfff..fffe1), | ||
1379 | * which gives us three upper bits in LSB to play with. | ||
1380 | */ | ||
1381 | //KEYCODE_SHIFT_TAB = (-12) & ~0x80, | ||
1382 | //KEYCODE_SHIFT_... = KEYCODE_... & ~0x80, | ||
1383 | //KEYCODE_CTRL_UP = KEYCODE_UP & ~0x40, | ||
1384 | //KEYCODE_CTRL_DOWN = KEYCODE_DOWN & ~0x40, | ||
1364 | KEYCODE_CTRL_RIGHT = KEYCODE_RIGHT & ~0x40, | 1385 | KEYCODE_CTRL_RIGHT = KEYCODE_RIGHT & ~0x40, |
1365 | KEYCODE_CTRL_LEFT = KEYCODE_LEFT & ~0x40, | 1386 | KEYCODE_CTRL_LEFT = KEYCODE_LEFT & ~0x40, |
1366 | #if 0 | 1387 | //KEYCODE_ALT_UP = KEYCODE_UP & ~0x20, |
1367 | KEYCODE_FUN1 = -12, | 1388 | //KEYCODE_ALT_DOWN = KEYCODE_DOWN & ~0x20, |
1368 | KEYCODE_FUN2 = -13, | 1389 | KEYCODE_ALT_RIGHT = KEYCODE_RIGHT & ~0x20, |
1369 | KEYCODE_FUN3 = -14, | 1390 | KEYCODE_ALT_LEFT = KEYCODE_LEFT & ~0x20, |
1370 | KEYCODE_FUN4 = -15, | 1391 | |
1371 | KEYCODE_FUN5 = -16, | ||
1372 | KEYCODE_FUN6 = -17, | ||
1373 | KEYCODE_FUN7 = -18, | ||
1374 | KEYCODE_FUN8 = -19, | ||
1375 | KEYCODE_FUN9 = -20, | ||
1376 | KEYCODE_FUN10 = -21, | ||
1377 | KEYCODE_FUN11 = -22, | ||
1378 | KEYCODE_FUN12 = -23, | ||
1379 | #endif | ||
1380 | KEYCODE_CURSOR_POS = -0x100, /* 0xfff..fff00 */ | 1392 | KEYCODE_CURSOR_POS = -0x100, /* 0xfff..fff00 */ |
1381 | /* How long is the longest ESC sequence we know? | 1393 | /* How long is the longest ESC sequence we know? |
1382 | * We want it big enough to be able to contain | 1394 | * We want it big enough to be able to contain |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 603bbfcae..0d232889b 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 | |||
2504 | vi_cmdmode = 1; | 2504 | vi_cmdmode = 1; |
2505 | input_backward(1); | 2505 | input_backward(1); |
2506 | } | 2506 | } |
2507 | /* Handle a few ESC-<key> combinations the same way | ||
2508 | * standard readline bindings (IOW: bash) do. | ||
2509 | * Often, Alt-<key> generates ESC-<key>. | ||
2510 | */ | ||
2511 | ic = lineedit_read_key(read_key_buffer, timeout); | ||
2512 | switch (ic) { | ||
2513 | //case KEYCODE_LEFT: - bash doesn't do this | ||
2514 | case 'b': | ||
2515 | ctrl_left(); | ||
2516 | break; | ||
2517 | //case KEYCODE_RIGHT: - bash doesn't do this | ||
2518 | case 'f': | ||
2519 | ctrl_right(); | ||
2520 | break; | ||
2521 | //case KEYCODE_DELETE: - bash doesn't do this | ||
2522 | case 'd': /* Alt-D */ | ||
2523 | { | ||
2524 | /* Delete word forward */ | ||
2525 | int nc, sc = cursor; | ||
2526 | ctrl_right(); | ||
2527 | nc = cursor; | ||
2528 | input_backward(cursor - sc); | ||
2529 | while (--nc >= cursor) | ||
2530 | input_delete(1); | ||
2531 | break; | ||
2532 | } | ||
2533 | case '\b': /* Alt-Backspace(?) */ | ||
2534 | case '\x7f': /* Alt-Backspace(?) */ | ||
2535 | //case 'w': - bash doesn't do this | ||
2536 | { | ||
2537 | /* Delete word backward */ | ||
2538 | int sc = cursor; | ||
2539 | ctrl_left(); | ||
2540 | while (sc-- > cursor) | ||
2541 | input_delete(1); | ||
2542 | break; | ||
2543 | } | ||
2544 | } | ||
2507 | break; | 2545 | break; |
2508 | #endif /* FEATURE_COMMAND_EDITING_VI */ | 2546 | #endif /* FEATURE_COMMAND_EDITING_VI */ |
2509 | 2547 | ||
@@ -2532,9 +2570,11 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2532 | input_backward(1); | 2570 | input_backward(1); |
2533 | break; | 2571 | break; |
2534 | case KEYCODE_CTRL_LEFT: | 2572 | case KEYCODE_CTRL_LEFT: |
2573 | case KEYCODE_ALT_LEFT: /* bash doesn't do it */ | ||
2535 | ctrl_left(); | 2574 | ctrl_left(); |
2536 | break; | 2575 | break; |
2537 | case KEYCODE_CTRL_RIGHT: | 2576 | case KEYCODE_CTRL_RIGHT: |
2577 | case KEYCODE_ALT_RIGHT: /* bash doesn't do it */ | ||
2538 | ctrl_right(); | 2578 | ctrl_right(); |
2539 | break; | 2579 | break; |
2540 | case KEYCODE_HOME: | 2580 | case KEYCODE_HOME: |
diff --git a/libbb/read_key.c b/libbb/read_key.c index 5dcd19c3f..8d72d2a63 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) | |||
40 | '[','C' |0x80,KEYCODE_RIGHT , | 40 | '[','C' |0x80,KEYCODE_RIGHT , |
41 | '[','D' |0x80,KEYCODE_LEFT , | 41 | '[','D' |0x80,KEYCODE_LEFT , |
42 | /* ESC [ 1 ; 2 x, where x = A/B/C/D: Shift-<arrow> */ | 42 | /* ESC [ 1 ; 2 x, where x = A/B/C/D: Shift-<arrow> */ |
43 | /* ESC [ 1 ; 3 x, where x = A/B/C/D: Alt-<arrow> */ | 43 | /* ESC [ 1 ; 3 x, where x = A/B/C/D: Alt-<arrow> - implemented below */ |
44 | /* ESC [ 1 ; 4 x, where x = A/B/C/D: Alt-Shift-<arrow> */ | 44 | /* ESC [ 1 ; 4 x, where x = A/B/C/D: Alt-Shift-<arrow> */ |
45 | /* ESC [ 1 ; 5 x, where x = A/B/C/D: Ctrl-<arrow> - implemented below */ | 45 | /* ESC [ 1 ; 5 x, where x = A/B/C/D: Ctrl-<arrow> - implemented below */ |
46 | /* ESC [ 1 ; 6 x, where x = A/B/C/D: Ctrl-Shift-<arrow> */ | 46 | /* ESC [ 1 ; 6 x, where x = A/B/C/D: Ctrl-Shift-<arrow> */ |
47 | '[','H' |0x80,KEYCODE_HOME , /* xterm */ | 47 | '[','H' |0x80,KEYCODE_HOME , /* xterm */ |
48 | /* [ESC] ESC [ [2] H - [Alt-][Shift-]Home */ | ||
49 | '[','F' |0x80,KEYCODE_END , /* xterm */ | 48 | '[','F' |0x80,KEYCODE_END , /* xterm */ |
49 | /* [ESC] ESC [ [2] H - [Alt-][Shift-]Home (End similarly?) */ | ||
50 | /* '[','Z' |0x80,KEYCODE_SHIFT_TAB, */ | ||
50 | '[','1','~' |0x80,KEYCODE_HOME , /* vt100? linux vt? or what? */ | 51 | '[','1','~' |0x80,KEYCODE_HOME , /* vt100? linux vt? or what? */ |
51 | '[','2','~' |0x80,KEYCODE_INSERT , | 52 | '[','2','~' |0x80,KEYCODE_INSERT , |
52 | /* ESC [ 2 ; 3 ~ - Alt-Insert */ | 53 | /* ESC [ 2 ; 3 ~ - Alt-Insert */ |
@@ -86,8 +87,12 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) | |||
86 | /* '[','1',';','5','B' |0x80,KEYCODE_CTRL_DOWN , - unused */ | 87 | /* '[','1',';','5','B' |0x80,KEYCODE_CTRL_DOWN , - unused */ |
87 | '[','1',';','5','C' |0x80,KEYCODE_CTRL_RIGHT, | 88 | '[','1',';','5','C' |0x80,KEYCODE_CTRL_RIGHT, |
88 | '[','1',';','5','D' |0x80,KEYCODE_CTRL_LEFT , | 89 | '[','1',';','5','D' |0x80,KEYCODE_CTRL_LEFT , |
90 | /* '[','1',';','3','A' |0x80,KEYCODE_ALT_UP , - unused */ | ||
91 | /* '[','1',';','3','B' |0x80,KEYCODE_ALT_DOWN , - unused */ | ||
92 | '[','1',';','3','C' |0x80,KEYCODE_ALT_RIGHT, | ||
93 | '[','1',';','3','D' |0x80,KEYCODE_ALT_LEFT , | ||
94 | /* '[','3',';','3','~' |0x80,KEYCODE_ALT_DELETE, - unused */ | ||
89 | 0 | 95 | 0 |
90 | /* ESC [ Z - Shift-Tab */ | ||
91 | }; | 96 | }; |
92 | 97 | ||
93 | pfd.fd = fd; | 98 | pfd.fd = fd; |