[PATCH] ui/ncurses: Handle arrow key variants

Samuel Mendoza-Jonas sam at mendozajonas.com
Mon Nov 20 15:44:47 AEDT 2017


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 at mendozajonas.com>
---
 ui/ncurses/nc-cui.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c
index 8060510..64b1f64 100644
--- a/ui/ncurses/nc-cui.c
+++ b/ui/ncurses/nc-cui.c
@@ -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 */
-- 
2.15.0



More information about the Petitboot mailing list