Fix CSI u parsing of some special keys

This commit is contained in:
Maxime Coste 2020-05-12 08:50:27 +10:00
parent 60154300f9
commit 151eb3299d

View File

@ -605,22 +605,25 @@ Optional<Key> NCursesUI::get_next_key()
if (not c) if (not c)
return {}; return {};
auto parse_key = [](unsigned char c) -> Key { static constexpr auto convert = [](Codepoint c) -> Codepoint {
if (c == control('m') or c == control('j')) if (c == control('m') or c == control('j'))
return {Key::Return}; return Key::Return;
if (c == control('i')) if (c == control('i'))
return {Key::Tab}; return Key::Tab;
if (c == control('h')) if (c == control('h') or c == 127)
return {Key::Backspace}; 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')) if (c == control('z'))
{ {
kill(0, SIGTSTP); // We suspend at this line kill(0, SIGTSTP); // We suspend at this line
return {}; return {};
} }
if (c < 27) if (c < 27)
return ctrl(Codepoint(c) - 1 + 'a'); return ctrl(c - 1 + 'a');
if (c == 127)
return {Key::Backspace};
struct Sentinel{}; struct Sentinel{};
struct CharIterator struct CharIterator
@ -735,7 +738,7 @@ Optional<Key> NCursesUI::get_next_key()
} }
return {}; return {};
case 'u': case 'u':
return masked_key(static_cast<Codepoint>(params[0])); return masked_key(convert(static_cast<Codepoint>(params[0])));
case 'Z': return shift(Key::Tab); case 'Z': return shift(Key::Tab);
case 'I': return {Key::FocusIn}; case 'I': return {Key::FocusIn};
case 'O': return {Key::FocusOut}; case 'O': return {Key::FocusOut};