Skip to content

Commit

Permalink
ui/ncurses: Handle arrow key variants
Browse files Browse the repository at this point in the history
In the vt100 'application' cursor mode arrow keys produce ^[Ox rather
than the usual ^[[x. Add this pattern to our defined keys so we don't
accidentally catch the escape key.

For reference:
http://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-21.html

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
  • Loading branch information
sammj committed Nov 21, 2017
1 parent 3a76e42 commit 33a0f54
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ui/ncurses/nc-cui.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,18 @@ static void cui_start(void)
define_key("\x1b\x4f\x46", KEY_END);
define_key("OH", KEY_HOME);
define_key("OF", KEY_END);

/* Arrow keys in normal cursor mode */
define_key("\x1b\x5b\x41", KEY_UP);
define_key("\x1b\x5b\x42", KEY_DOWN);
define_key("\x1b\x5b\x43", KEY_RIGHT);
define_key("\x1b\x5b\x44", KEY_LEFT);
/* Arrow keys in "application" cursor mode */
define_key("\x1b\x4f\x41", KEY_UP);
define_key("\x1b\x4f\x42", KEY_DOWN);
define_key("\x1b\x4f\x43", KEY_RIGHT);
define_key("\x1b\x4f\x44", KEY_LEFT);

define_key("\x1b\x5b\x33\x7e", KEY_DC);

while (getch() != ERR) /* flush stdin */
Expand Down

0 comments on commit 33a0f54

Please sign in to comment.