From df6d0355d6b2a3ce4c92309ab73c9d839af5d2c1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 22 Sep 2019 09:16:08 +1000 Subject: [PATCH] Add support for parsing SS3 key sequences As discussed on #3087, fixes part of that issue. --- src/ncurses_ui.cc | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 81688a86..8f9dac98 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -772,16 +772,32 @@ Optional NCursesUI::get_next_key() return {}; }; + auto parse_ss3 = [this]() -> Optional { + switch (get_char().value_or((unsigned char)0xff)) + { + case 'A': return Key{Key::Up}; + case 'B': return Key{Key::Down}; + case 'C': return Key{Key::Right}; + case 'D': return Key{Key::Left}; + case 'F': return Key{Key::End}; + case 'H': return Key{Key::Home}; + case 'P': return Key{Key::F1}; + case 'Q': return Key{Key::F2}; + case 'R': return Key{Key::F3}; + case 'S': return Key{Key::F4}; + default: return {}; + } + }; + if (*c != 27) return parse_key(*c); if (auto next = get_char()) { if (*next == '[') // potential CSI - { - if (auto key = parse_csi()) - return key; - } + return parse_csi().value_or(alt('[')); + if (*next == 'O') // potential SS3 + return parse_ss3().value_or(alt('O')); return alt(parse_key(*next)); } return Key{Key::Escape};