Convert \r into \n (#350)

This resolves:
https://github.com/ArthurSonzogni/FTXUI/issues/337
This commit is contained in:
Arthur Sonzogni 2022-03-04 13:23:45 +01:00 committed by GitHub
parent a254e36632
commit 3e28fd6520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View File

@ -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
-----

View File

@ -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");

View File

@ -52,6 +52,13 @@ void TerminalInputParser::Send(TerminalInputParser::Output output) {
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_)));
pending_.clear();
return;