From 151eb3299d3bf3c966eaa1ff689e0866b7e08ef6 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 12 May 2020 08:50:27 +1000 Subject: [PATCH] Fix CSI u parsing of some special keys --- src/ncurses_ui.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 4783b823..0f37abfd 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -605,22 +605,25 @@ Optional NCursesUI::get_next_key() if (not c) return {}; - auto parse_key = [](unsigned char c) -> Key { + static constexpr auto convert = [](Codepoint c) -> Codepoint { if (c == control('m') or c == control('j')) - return {Key::Return}; + return Key::Return; if (c == control('i')) - return {Key::Tab}; - if (c == control('h')) - return {Key::Backspace}; + return Key::Tab; + if (c == control('h') or c == 127) + return Key::Backspace; + return c; + }; + auto parse_key = [](unsigned char c) -> Key { + if (Codepoint cp = convert(c); cp > 255) + return Key{cp}; if (c == control('z')) { kill(0, SIGTSTP); // We suspend at this line return {}; } if (c < 27) - return ctrl(Codepoint(c) - 1 + 'a'); - if (c == 127) - return {Key::Backspace}; + return ctrl(c - 1 + 'a'); struct Sentinel{}; struct CharIterator @@ -735,7 +738,7 @@ Optional NCursesUI::get_next_key() } return {}; case 'u': - return masked_key(static_cast(params[0])); + return masked_key(convert(static_cast(params[0]))); case 'Z': return shift(Key::Tab); case 'I': return {Key::FocusIn}; case 'O': return {Key::FocusOut};