mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-17 08:28:09 +08:00
Fix F1-F4 keymapping. (#501)
It was just wrong, even on Linux. Bug:https://github.com/ArthurSonzogni/FTXUI/issues/492
This commit is contained in:
@@ -65,18 +65,22 @@ const Event Event::Escape = Event::Special("\x1B"); // NOLINT
|
||||
const Event Event::Return = Event::Special({10}); // NOLINT
|
||||
const Event Event::Tab = Event::Special({9}); // NOLINT
|
||||
const Event Event::TabReverse = Event::Special({27, 91, 90}); // NOLINT
|
||||
const Event Event::F1 = Event::Special("\x1B[OP"); // NOLINT
|
||||
const Event Event::F2 = Event::Special("\x1B[OQ"); // NOLINT
|
||||
const Event Event::F3 = Event::Special("\x1B[OR"); // NOLINT
|
||||
const Event Event::F4 = Event::Special("\x1B[OS"); // NOLINT
|
||||
const Event Event::F5 = Event::Special("\x1B[15~"); // NOLINT
|
||||
const Event Event::F6 = Event::Special("\x1B[17~"); // NOLINT
|
||||
const Event Event::F7 = Event::Special("\x1B[18~"); // NOLINT
|
||||
const Event Event::F8 = Event::Special("\x1B[19~"); // NOLINT
|
||||
const Event Event::F9 = Event::Special("\x1B[20~"); // NOLINT
|
||||
const Event Event::F10 = Event::Special("\x1B[21~"); // NOLINT
|
||||
const Event Event::F11 = Event::Special("\x1B[21~"); // Doesn't exist // NOLINT
|
||||
|
||||
// See https://invisible-island.net/xterm/xterm-function-keys.html
|
||||
// We follow xterm-new / vterm-xf86-v4 / mgt / screen
|
||||
const Event Event::F1 = Event::Special("\x1BOP"); // NOLINT
|
||||
const Event Event::F2 = Event::Special("\x1BOQ"); // NOLINT
|
||||
const Event Event::F3 = Event::Special("\x1BOR"); // NOLINT
|
||||
const Event Event::F4 = Event::Special("\x1BOS"); // NOLINT
|
||||
const Event Event::F5 = Event::Special("\x1B[15~"); // NOLINT
|
||||
const Event Event::F6 = Event::Special("\x1B[17~"); // NOLINT
|
||||
const Event Event::F7 = Event::Special("\x1B[18~"); // NOLINT
|
||||
const Event Event::F8 = Event::Special("\x1B[19~"); // NOLINT
|
||||
const Event Event::F9 = Event::Special("\x1B[20~"); // NOLINT
|
||||
const Event Event::F10 = Event::Special("\x1B[21~"); // NOLINT
|
||||
const Event Event::F11 = Event::Special("\x1B[23~"); // NOLINT
|
||||
const Event Event::F12 = Event::Special("\x1B[24~"); // NOLINT
|
||||
|
||||
const Event Event::Home = Event::Special({27, 91, 72}); // NOLINT
|
||||
const Event Event::End = Event::Special({27, 91, 70}); // NOLINT
|
||||
const Event Event::PageUp = Event::Special({27, 91, 53, 126}); // NOLINT
|
||||
|
@@ -48,7 +48,7 @@ bool IsWordCharacter(WordBreakProperty property) {
|
||||
case WordBreakProperty::Regional_Indicator:
|
||||
case WordBreakProperty::ZWJ:
|
||||
return false;
|
||||
};
|
||||
}
|
||||
return true; // NOT_REACHED();
|
||||
}
|
||||
|
||||
|
@@ -3,14 +3,24 @@
|
||||
#include <cstdint> // for uint32_t
|
||||
#include <ftxui/component/mouse.hpp> // for Mouse, Mouse::Button, Mouse::Motion
|
||||
#include <ftxui/component/receiver.hpp> // for SenderImpl, Sender
|
||||
#include <memory> // for unique_ptr, allocator
|
||||
#include <utility> // for move
|
||||
#include <map>
|
||||
#include <memory> // for unique_ptr, allocator
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/component/event.hpp" // for Event
|
||||
#include "ftxui/component/task.hpp" // for Task
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
const std::map<std::string, std::string> g_uniformize = {{
|
||||
// Microsoft's terminal uses a different new line character for the return
|
||||
// key. This also happens with linux with the `bind` command:
|
||||
// See https://github.com/ArthurSonzogni/FTXUI/issues/337
|
||||
// Here, we uniformize the new line character to `\n`.
|
||||
{"\r", "\n"},
|
||||
}};
|
||||
|
||||
TerminalInputParser::TerminalInputParser(Sender<Task> out)
|
||||
: out_(std::move(out)) {}
|
||||
|
||||
@@ -56,17 +66,14 @@ void TerminalInputParser::Send(TerminalInputParser::Output output) {
|
||||
pending_.clear();
|
||||
return;
|
||||
|
||||
case SPECIAL:
|
||||
// Microsoft's terminal uses a different new line character for the return
|
||||
// key. This also happens with linux with the `bind` command:
|
||||
// See https://github.com/ArthurSonzogni/FTXUI/issues/337
|
||||
// Here, we uniformize the new line character to `\n`.
|
||||
if (pending_ == "\r") {
|
||||
out_->Send(Event::Special("\n"));
|
||||
} else {
|
||||
out_->Send(Event::Special(std::move(pending_)));
|
||||
case SPECIAL: {
|
||||
auto it = g_uniformize.find(pending_);
|
||||
if (it != g_uniformize.end()) {
|
||||
pending_ = it->second;
|
||||
}
|
||||
out_->Send(Event::Special(std::move(pending_)));
|
||||
pending_.clear();
|
||||
}
|
||||
return;
|
||||
|
||||
case MOUSE:
|
||||
|
@@ -347,17 +347,17 @@ TEST(Event, Special) {
|
||||
{{10}, Event::Return},
|
||||
{{9}, Event::Tab},
|
||||
{{27, 91, 90}, Event::TabReverse},
|
||||
//{str("\x1B[OP"), Event::F1},
|
||||
//{str("\x1B[OQ"), Event::F2},
|
||||
//{str("\x1B[OR"), Event::F3},
|
||||
//{str("\x1B[OS"), Event::F4},
|
||||
{str("\x1BOP"), Event::F1},
|
||||
{str("\x1BOQ"), Event::F2},
|
||||
{str("\x1BOR"), Event::F3},
|
||||
{str("\x1BOS"), Event::F4},
|
||||
{str("\x1B[15~"), Event::F5},
|
||||
{str("\x1B[17~"), Event::F6},
|
||||
{str("\x1B[18~"), Event::F7},
|
||||
{str("\x1B[19~"), Event::F8},
|
||||
{str("\x1B[20~"), Event::F9},
|
||||
{str("\x1B[21~"), Event::F10},
|
||||
{str("\x1B[21~"), Event::F11},
|
||||
{str("\x1B[23~"), Event::F11},
|
||||
{str("\x1B[24~"), Event::F12},
|
||||
{{27, 91, 72}, Event::Home},
|
||||
{{27, 91, 70}, Event::End},
|
||||
|
Reference in New Issue
Block a user