From 2e4ef38743c3d4aef109b5cc04429ec1f0e2f6c8 Mon Sep 17 00:00:00 2001 From: Rostislav Skudnov Date: Thu, 24 Nov 2016 15:04:00 +0100 Subject: lineedit: fix handling of repeating Alt-b, Alt-f, Alt-d, Alt-Backspace These key combinations should repeat correctly when the keys are pressed and held. Before this change, they do this erratically - many repeats are "eaten" because they are treated as unrecognized ESC seqs: ESC 0x7f is treated by Alt+baskspace, but ESC 0x7f ESC 0x7f ESC 0x7f is unrecognized. Escape sequences corresponding to these key combinations are moved from read_line_input to lineedit_read_key. Also, these key sequences are now enabled regardless of whether FEATURE_EDITING_VI is set, since Vim does not actually support these key combinations, but they are present in readline library. function old new delta static.esccmds 93 103 +10 read_line_input 3737 3687 -50 Signed-off-by: Rostislav Skudnov Signed-off-by: Denys Vlasenko --- libbb/read_key.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libbb/read_key.c') diff --git a/libbb/read_key.c b/libbb/read_key.c index ace23defb..951786869 100644 --- a/libbb/read_key.c +++ b/libbb/read_key.c @@ -18,8 +18,20 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) /* Known escape sequences for cursor and function keys. * See "Xterm Control Sequences" * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html + * Array should be sorted from shortest to longest. */ static const char esccmds[] ALIGN1 = { + '\x7f' |0x80,KEYCODE_ALT_BACKSPACE, + '\b' |0x80,KEYCODE_ALT_BACKSPACE, + 'd' |0x80,KEYCODE_ALT_D , + /* lineedit mimics bash: Alt-f and Alt-b are forward/backward + * word jumps. We cheat here and make them return ALT_LEFT/RIGHT + * keycodes. This way, lineedit need no special code to handle them. + * If we'll need to distinguish them, introduce new ALT_F/B keycodes, + * and update lineedit to react to them. + */ + 'f' |0x80,KEYCODE_ALT_RIGHT, + 'b' |0x80,KEYCODE_ALT_LEFT, 'O','A' |0x80,KEYCODE_UP , 'O','B' |0x80,KEYCODE_DOWN , 'O','C' |0x80,KEYCODE_RIGHT , -- cgit v1.2.3