Add support for parsing SS3 key sequences

As discussed on #3087, fixes part of that issue.
This commit is contained in:
Maxime Coste 2019-09-22 09:16:08 +10:00
parent 271b1d4f2f
commit df6d0355d6

View File

@ -772,16 +772,32 @@ Optional<Key> NCursesUI::get_next_key()
return {};
};
auto parse_ss3 = [this]() -> Optional<Key> {
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};