Support F1-F5 from OS terminal (#687)

Bug:https://github.com/ArthurSonzogni/FTXUI/issues/685
This commit is contained in:
Arthur Sonzogni 2023-06-24 17:15:23 +02:00 committed by ArthurSonzogni
parent 46042ce74a
commit 2ed61a9d31
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C
3 changed files with 23 additions and 1 deletions

View File

@ -5,6 +5,7 @@ Changelog
--- ---
### Component ### Component
- Bugfix: Support F1-F5 from OS terminal.
### Dom ### Dom
- Feature: Add `hyperlink` decorator. For instance: - Feature: Add `hyperlink` decorator. For instance:

View File

@ -44,6 +44,13 @@ const std::map<std::string, std::string> g_uniformize = {
{"\x1BOH", "\x1B[H"}, // HOME {"\x1BOH", "\x1B[H"}, // HOME
{"\x1BOF", "\x1B[F"}, // END {"\x1BOF", "\x1B[F"}, // END
// Variations around the FN keys.
// See: https://github.com/ArthurSonzogni/FTXUI/issues/685
{"\x1B[[A", "\x1BOP"}, // F1
{"\x1B[[B", "\x1BOQ"}, // F2
{"\x1B[[C", "\x1BOR"}, // F3
{"\x1B[[D", "\x1BOS"}, // F4
{"\x1B[[E", "\x1B[15~"}, // F5
}; };
TerminalInputParser::TerminalInputParser(Sender<Task> out) TerminalInputParser::TerminalInputParser(Sender<Task> out)
@ -291,9 +298,16 @@ TerminalInputParser::Output TerminalInputParser::ParseCSI() {
continue; continue;
} }
if (Current() >= ' ' && Current() <= '~' && Current() != '<') { // CSI is terminated by a character in the range 0x400x7E
// (ASCII @AZ[\]^_`az{|}~),
if (Current() >= '@' && Current() <= '~' &&
// Note: I don't remember why we exclude '<'
Current() != '<' &&
// To handle F1-F4, we exclude '['.
Current() != '[') {
arguments.push_back(argument); arguments.push_back(argument);
argument = 0; // NOLINT argument = 0; // NOLINT
switch (Current()) { switch (Current()) {
case 'M': case 'M':
return ParseMouse(altered, true, std::move(arguments)); return ParseMouse(altered, true, std::move(arguments));

View File

@ -384,6 +384,13 @@ TEST(Event, Special) {
{str("\x1B[23~"), Event::F11}, {str("\x1B[23~"), Event::F11},
{str("\x1B[24~"), Event::F12}, {str("\x1B[24~"), Event::F12},
// Function keys for virtual terminal:
{str("\x1B[[A"), Event::F1},
{str("\x1B[[B"), Event::F2},
{str("\x1B[[C"), Event::F3},
{str("\x1B[[D"), Event::F4},
{str("\x1B[[E"), Event::F5},
// Page up and down: // Page up and down:
{str("\x1B[5~"), Event::PageUp}, {str("\x1B[5~"), Event::PageUp},
{str("\x1B[6~"), Event::PageDown}, {str("\x1B[6~"), Event::PageDown},