From 3e28fd6520af424cc19c90971a924c0244389791 Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Fri, 4 Mar 2022 13:23:45 +0100 Subject: [PATCH] Convert \r into \n (#350) This resolves: https://github.com/ArthurSonzogni/FTXUI/issues/337 --- CHANGELOG.md | 3 +++ src/ftxui/component/event.cpp | 4 ---- src/ftxui/component/terminal_input_parser.cpp | 9 ++++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2125365..9a5f55c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,9 @@ Element gaugeDirection(float ratio, GaugeDirection); - **bugfix** Container::Tab implements `Focusable()`. - **bugfix** Improved default implementations of ComponentBase `Focusable()` and `ActiveChild()` methods. +- **bugfix** Automatically convert '\r' keys into '\n' for Linux programs that + do not send the correct code for the return key, like the 'bind'. + https://github.com/ArthurSonzogni/FTXUI/issues/337 2.0.0 ----- diff --git a/src/ftxui/component/event.cpp b/src/ftxui/component/event.cpp index ecb8c0f..9c797bd 100644 --- a/src/ftxui/component/event.cpp +++ b/src/ftxui/component/event.cpp @@ -58,11 +58,7 @@ const Event Event::ArrowDown = Event::Special("\x1B[B"); const Event Event::Backspace = Event::Special({127}); const Event Event::Delete = Event::Special("\x1B[3~"); const Event Event::Escape = Event::Special("\x1B"); -#if defined(_WIN32) -const Event Event::Return = Event::Special({13}); -#else const Event Event::Return = Event::Special({10}); -#endif const Event Event::Tab = Event::Special({9}); const Event Event::TabReverse = Event::Special({27, 91, 90}); const Event Event::F1 = Event::Special("\x1B[OP"); diff --git a/src/ftxui/component/terminal_input_parser.cpp b/src/ftxui/component/terminal_input_parser.cpp index 22da7dc..ae9f45a 100644 --- a/src/ftxui/component/terminal_input_parser.cpp +++ b/src/ftxui/component/terminal_input_parser.cpp @@ -52,7 +52,14 @@ void TerminalInputParser::Send(TerminalInputParser::Output output) { return; case SPECIAL: - out_->Send(Event::Special(std::move(pending_))); + // 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_))); pending_.clear(); return;