From 092482f63be72ddcaf4c01e6436f1a0629e7a2d9 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Sat, 27 Apr 2024 20:49:49 +0200 Subject: [PATCH] Fix Event.Control test. --- examples/component/print_key_press.cpp | 8 +- .../ftxui/component/screen_interactive.hpp | 8 +- include/ftxui/dom/canvas.hpp | 6 +- include/ftxui/screen/screen.hpp | 3 +- src/ftxui/component/event.cpp | 314 ++++++++++-------- src/ftxui/component/screen_interactive.cpp | 8 +- src/ftxui/component/terminal_input_parser.cpp | 5 +- .../component/terminal_input_parser_test.cpp | 13 +- src/ftxui/dom/canvas.cpp | 2 +- src/ftxui/screen/image.cpp | 13 +- src/ftxui/screen/screen.cpp | 6 +- 11 files changed, 216 insertions(+), 170 deletions(-) diff --git a/examples/component/print_key_press.cpp b/examples/component/print_key_press.cpp index 3d4227c8..8c2216ae 100644 --- a/examples/component/print_key_press.cpp +++ b/examples/component/print_key_press.cpp @@ -33,8 +33,8 @@ int main() { auto left_column = Renderer([&] { Elements children = { - text("Codes"), - separator(), + text("Codes"), + separator(), }; for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) { children.push_back(text(Code(keys[i]))); @@ -44,8 +44,8 @@ int main() { auto right_column = Renderer([&] { Elements children = { - text("Event"), - separator(), + text("Event"), + separator(), }; for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) { children.push_back(text(keys[i].DebugString())); diff --git a/include/ftxui/component/screen_interactive.hpp b/include/ftxui/component/screen_interactive.hpp index e1311979..bbbae0fe 100644 --- a/include/ftxui/component/screen_interactive.hpp +++ b/include/ftxui/component/screen_interactive.hpp @@ -59,12 +59,12 @@ class ScreenInteractive : public Screen { // temporarily uninstalled. Closure WithRestoredIO(Closure); - // FTXUI implements handlers for Ctrl-C and Ctrl-Z. By default, these handlers + // FTXUI implements handlers for Ctrl-C and Ctrl-Z. By default, these handlers // are executed, even if the component catches the event. This avoid users // handling every event to be trapped in the application. However, in some - // cases, the application may want to handle these events itself. In this case, - // the application can force FTXUI to not handle these events by calling the - // following functions with force=true. + // cases, the application may want to handle these events itself. In this + // case, the application can force FTXUI to not handle these events by calling + // the following functions with force=true. void ForceHandleCtrlC(bool force); void ForceHandleCtrlZ(bool force); diff --git a/include/ftxui/dom/canvas.hpp b/include/ftxui/dom/canvas.hpp index ffc487c7..5d33d67a 100644 --- a/include/ftxui/dom/canvas.hpp +++ b/include/ftxui/dom/canvas.hpp @@ -9,8 +9,8 @@ #include // for string #include // for unordered_map -#include "ftxui/screen/color.hpp" // for Color -#include "ftxui/screen/image.hpp" // for Pixel, Image +#include "ftxui/screen/color.hpp" // for Color +#include "ftxui/screen/image.hpp" // for Pixel, Image #ifdef DrawText // Workaround for WinUsr.h (via Windows.h) defining macros that break things. @@ -94,7 +94,7 @@ struct Canvas { void DrawText(int x, int y, const std::string& value); void DrawText(int x, int y, const std::string& value, const Color& color); void DrawText(int x, int y, const std::string& value, const Stylizer& style); - + // Draw using directly pixels or images -------------------------------------- // x is considered to be a multiple of 2. // y is considered to be a multiple of 4. diff --git a/include/ftxui/screen/screen.hpp b/include/ftxui/screen/screen.hpp index 6dd6eedf..2bc77a60 100644 --- a/include/ftxui/screen/screen.hpp +++ b/include/ftxui/screen/screen.hpp @@ -36,7 +36,8 @@ class Screen : public Image { // Print the Screen on to the terminal. void Print() const; - // Fill the screen with space and reset any screen state, like hyperlinks, and cursor + // Fill the screen with space and reset any screen state, like hyperlinks, and + // cursor void Clear(); // Move the terminal cursor n-lines up with n = dimy(). diff --git a/src/ftxui/component/event.cpp b/src/ftxui/component/event.cpp index 381c21de..12dd20bf 100644 --- a/src/ftxui/component/event.cpp +++ b/src/ftxui/component/event.cpp @@ -229,7 +229,7 @@ std::string Event::DebugString() const { {Mouse::Motion::Moved, ".motion = Mouse::Moved"}, }; - switch(type_) { + switch (type_) { case Type::Character: { return "Event::Character(\"" + input_ + "\")"; } @@ -311,139 +311,191 @@ const Event Event::PageUp = Event::Special({27, 91, 53, 126}); // NOLINT const Event Event::PageDown = Event::Special({27, 91, 54, 126}); // NOLINT const Event Event::Custom = Event::Special({0}); // NOLINT // -const Event Event::a = Event::Character("a"); // NOLINT -const Event Event::b = Event::Character("b"); // NOLINT -const Event Event::c = Event::Character("c"); // NOLINT -const Event Event::d = Event::Character("d"); // NOLINT -const Event Event::e = Event::Character("e"); // NOLINT -const Event Event::f = Event::Character("f"); // NOLINT -const Event Event::g = Event::Character("g"); // NOLINT -const Event Event::h = Event::Character("h"); // NOLINT -const Event Event::i = Event::Character("i"); // NOLINT -const Event Event::j = Event::Character("j"); // NOLINT -const Event Event::k = Event::Character("k"); // NOLINT -const Event Event::l = Event::Character("l"); // NOLINT -const Event Event::m = Event::Character("m"); // NOLINT -const Event Event::n = Event::Character("n"); // NOLINT -const Event Event::o = Event::Character("o"); // NOLINT -const Event Event::p = Event::Character("p"); // NOLINT -const Event Event::q = Event::Character("q"); // NOLINT -const Event Event::r = Event::Character("r"); // NOLINT -const Event Event::s = Event::Character("s"); // NOLINT -const Event Event::t = Event::Character("t"); // NOLINT -const Event Event::u = Event::Character("u"); // NOLINT -const Event Event::v = Event::Character("v"); // NOLINT -const Event Event::w = Event::Character("w"); // NOLINT -const Event Event::x = Event::Character("x"); // NOLINT -const Event Event::y = Event::Character("y"); // NOLINT -const Event Event::z = Event::Character("z"); // NOLINT +const Event Event::a = Event::Character("a"); // NOLINT +const Event Event::b = Event::Character("b"); // NOLINT +const Event Event::c = Event::Character("c"); // NOLINT +const Event Event::d = Event::Character("d"); // NOLINT +const Event Event::e = Event::Character("e"); // NOLINT +const Event Event::f = Event::Character("f"); // NOLINT +const Event Event::g = Event::Character("g"); // NOLINT +const Event Event::h = Event::Character("h"); // NOLINT +const Event Event::i = Event::Character("i"); // NOLINT +const Event Event::j = Event::Character("j"); // NOLINT +const Event Event::k = Event::Character("k"); // NOLINT +const Event Event::l = Event::Character("l"); // NOLINT +const Event Event::m = Event::Character("m"); // NOLINT +const Event Event::n = Event::Character("n"); // NOLINT +const Event Event::o = Event::Character("o"); // NOLINT +const Event Event::p = Event::Character("p"); // NOLINT +const Event Event::q = Event::Character("q"); // NOLINT +const Event Event::r = Event::Character("r"); // NOLINT +const Event Event::s = Event::Character("s"); // NOLINT +const Event Event::t = Event::Character("t"); // NOLINT +const Event Event::u = Event::Character("u"); // NOLINT +const Event Event::v = Event::Character("v"); // NOLINT +const Event Event::w = Event::Character("w"); // NOLINT +const Event Event::x = Event::Character("x"); // NOLINT +const Event Event::y = Event::Character("y"); // NOLINT +const Event Event::z = Event::Character("z"); // NOLINT -const Event Event::A = Event::Character("A"); // NOLINT -const Event Event::B = Event::Character("B"); // NOLINT -const Event Event::C = Event::Character("C"); // NOLINT -const Event Event::D = Event::Character("D"); // NOLINT -const Event Event::E = Event::Character("E"); // NOLINT -const Event Event::F = Event::Character("F"); // NOLINT -const Event Event::G = Event::Character("G"); // NOLINT -const Event Event::H = Event::Character("H"); // NOLINT -const Event Event::I = Event::Character("I"); // NOLINT -const Event Event::J = Event::Character("J"); // NOLINT -const Event Event::K = Event::Character("K"); // NOLINT -const Event Event::L = Event::Character("L"); // NOLINT -const Event Event::M = Event::Character("M"); // NOLINT -const Event Event::N = Event::Character("N"); // NOLINT -const Event Event::O = Event::Character("O"); // NOLINT -const Event Event::P = Event::Character("P"); // NOLINT -const Event Event::Q = Event::Character("Q"); // NOLINT -const Event Event::R = Event::Character("R"); // NOLINT -const Event Event::S = Event::Character("S"); // NOLINT -const Event Event::T = Event::Character("T"); // NOLINT -const Event Event::U = Event::Character("U"); // NOLINT -const Event Event::V = Event::Character("V"); // NOLINT -const Event Event::W = Event::Character("W"); // NOLINT -const Event Event::X = Event::Character("X"); // NOLINT -const Event Event::Y = Event::Character("Y"); // NOLINT -const Event Event::Z = Event::Character("Z"); // NOLINT +const Event Event::A = Event::Character("A"); // NOLINT +const Event Event::B = Event::Character("B"); // NOLINT +const Event Event::C = Event::Character("C"); // NOLINT +const Event Event::D = Event::Character("D"); // NOLINT +const Event Event::E = Event::Character("E"); // NOLINT +const Event Event::F = Event::Character("F"); // NOLINT +const Event Event::G = Event::Character("G"); // NOLINT +const Event Event::H = Event::Character("H"); // NOLINT +const Event Event::I = Event::Character("I"); // NOLINT +const Event Event::J = Event::Character("J"); // NOLINT +const Event Event::K = Event::Character("K"); // NOLINT +const Event Event::L = Event::Character("L"); // NOLINT +const Event Event::M = Event::Character("M"); // NOLINT +const Event Event::N = Event::Character("N"); // NOLINT +const Event Event::O = Event::Character("O"); // NOLINT +const Event Event::P = Event::Character("P"); // NOLINT +const Event Event::Q = Event::Character("Q"); // NOLINT +const Event Event::R = Event::Character("R"); // NOLINT +const Event Event::S = Event::Character("S"); // NOLINT +const Event Event::T = Event::Character("T"); // NOLINT +const Event Event::U = Event::Character("U"); // NOLINT +const Event Event::V = Event::Character("V"); // NOLINT +const Event Event::W = Event::Character("W"); // NOLINT +const Event Event::X = Event::Character("X"); // NOLINT +const Event Event::Y = Event::Character("Y"); // NOLINT +const Event Event::Z = Event::Character("Z"); // NOLINT -const Event Event::CtrlA = Event::Special("\x01"); // NOLINT -const Event Event::CtrlB = Event::Special("\x02"); // NOLINT -const Event Event::CtrlC = Event::Special("\x03"); // NOLINT -const Event Event::CtrlD = Event::Special("\x04"); // NOLINT -const Event Event::CtrlE = Event::Special("\x05"); // NOLINT -const Event Event::CtrlF = Event::Special("\x06"); // NOLINT -const Event Event::CtrlG = Event::Special("\x07"); // NOLINT -const Event Event::CtrlH = Event::Special("\x08"); // NOLINT -const Event Event::CtrlI = Event::Special("\x09"); // NOLINT -const Event Event::CtrlJ = Event::Special("\x0a"); // NOLINT -const Event Event::CtrlK = Event::Special("\x0b"); // NOLINT -const Event Event::CtrlL = Event::Special("\x0c"); // NOLINT -const Event Event::CtrlM = Event::Special("\x0d"); // NOLINT -const Event Event::CtrlN = Event::Special("\x0e"); // NOLINT -const Event Event::CtrlO = Event::Special("\x0f"); // NOLINT -const Event Event::CtrlP = Event::Special("\x10"); // NOLINT -const Event Event::CtrlQ = Event::Special("\x11"); // NOLINT -const Event Event::CtrlR = Event::Special("\x12"); // NOLINT -const Event Event::CtrlS = Event::Special("\x13"); // NOLINT -const Event Event::CtrlT = Event::Special("\x14"); // NOLINT -const Event Event::CtrlU = Event::Special("\x15"); // NOLINT -const Event Event::CtrlV = Event::Special("\x16"); // NOLINT -const Event Event::CtrlW = Event::Special("\x17"); // NOLINT -const Event Event::CtrlX = Event::Special("\x18"); // NOLINT -const Event Event::CtrlY = Event::Special("\x19"); // NOLINT -const Event Event::CtrlZ = Event::Special("\x1a"); // NOLINT +const Event Event::CtrlA = Event::Special("\x01"); // NOLINT +const Event Event::CtrlB = Event::Special("\x02"); // NOLINT +const Event Event::CtrlC = Event::Special("\x03"); // NOLINT +const Event Event::CtrlD = Event::Special("\x04"); // NOLINT +const Event Event::CtrlE = Event::Special("\x05"); // NOLINT +const Event Event::CtrlF = Event::Special("\x06"); // NOLINT +const Event Event::CtrlG = Event::Special("\x07"); // NOLINT +const Event Event::CtrlH = Event::Special("\x08"); // NOLINT +const Event Event::CtrlI = Event::Special("\x09"); // NOLINT +const Event Event::CtrlJ = Event::Special("\x0a"); // NOLINT +const Event Event::CtrlK = Event::Special("\x0b"); // NOLINT +const Event Event::CtrlL = Event::Special("\x0c"); // NOLINT +const Event Event::CtrlM = Event::Special("\x0d"); // NOLINT +const Event Event::CtrlN = Event::Special("\x0e"); // NOLINT +const Event Event::CtrlO = Event::Special("\x0f"); // NOLINT +const Event Event::CtrlP = Event::Special("\x10"); // NOLINT +const Event Event::CtrlQ = Event::Special("\x11"); // NOLINT +const Event Event::CtrlR = Event::Special("\x12"); // NOLINT +const Event Event::CtrlS = Event::Special("\x13"); // NOLINT +const Event Event::CtrlT = Event::Special("\x14"); // NOLINT +const Event Event::CtrlU = Event::Special("\x15"); // NOLINT +const Event Event::CtrlV = Event::Special("\x16"); // NOLINT +const Event Event::CtrlW = Event::Special("\x17"); // NOLINT +const Event Event::CtrlX = Event::Special("\x18"); // NOLINT +const Event Event::CtrlY = Event::Special("\x19"); // NOLINT +const Event Event::CtrlZ = Event::Special("\x1a"); // NOLINT -const Event Event::AltA = Event::Special("\x1b""a"); // NOLINT -const Event Event::AltB = Event::Special("\x1b""b"); // NOLINT -const Event Event::AltC = Event::Special("\x1b""c"); // NOLINT -const Event Event::AltD = Event::Special("\x1b""d"); // NOLINT -const Event Event::AltE = Event::Special("\x1b""e"); // NOLINT -const Event Event::AltF = Event::Special("\x1b""f"); // NOLINT -const Event Event::AltG = Event::Special("\x1b""g"); // NOLINT -const Event Event::AltH = Event::Special("\x1b""h"); // NOLINT -const Event Event::AltI = Event::Special("\x1b""i"); // NOLINT -const Event Event::AltJ = Event::Special("\x1b""j"); // NOLINT -const Event Event::AltK = Event::Special("\x1b""k"); // NOLINT -const Event Event::AltL = Event::Special("\x1b""l"); // NOLINT -const Event Event::AltM = Event::Special("\x1b""m"); // NOLINT -const Event Event::AltN = Event::Special("\x1b""n"); // NOLINT -const Event Event::AltO = Event::Special("\x1b""o"); // NOLINT -const Event Event::AltP = Event::Special("\x1b""p"); // NOLINT -const Event Event::AltQ = Event::Special("\x1b""q"); // NOLINT -const Event Event::AltR = Event::Special("\x1b""r"); // NOLINT -const Event Event::AltS = Event::Special("\x1b""s"); // NOLINT -const Event Event::AltT = Event::Special("\x1b""t"); // NOLINT -const Event Event::AltU = Event::Special("\x1b""u"); // NOLINT -const Event Event::AltV = Event::Special("\x1b""v"); // NOLINT -const Event Event::AltW = Event::Special("\x1b""w"); // NOLINT -const Event Event::AltX = Event::Special("\x1b""x"); // NOLINT -const Event Event::AltY = Event::Special("\x1b""y"); // NOLINT -const Event Event::AltZ = Event::Special("\x1b""z"); // NOLINT +const Event Event::AltA = Event::Special( + "\x1b" + "a"); // NOLINT +const Event Event::AltB = Event::Special( + "\x1b" + "b"); // NOLINT +const Event Event::AltC = Event::Special( + "\x1b" + "c"); // NOLINT +const Event Event::AltD = Event::Special( + "\x1b" + "d"); // NOLINT +const Event Event::AltE = Event::Special( + "\x1b" + "e"); // NOLINT +const Event Event::AltF = Event::Special( + "\x1b" + "f"); // NOLINT +const Event Event::AltG = Event::Special( + "\x1b" + "g"); // NOLINT +const Event Event::AltH = Event::Special( + "\x1b" + "h"); // NOLINT +const Event Event::AltI = Event::Special( + "\x1b" + "i"); // NOLINT +const Event Event::AltJ = Event::Special( + "\x1b" + "j"); // NOLINT +const Event Event::AltK = Event::Special( + "\x1b" + "k"); // NOLINT +const Event Event::AltL = Event::Special( + "\x1b" + "l"); // NOLINT +const Event Event::AltM = Event::Special( + "\x1b" + "m"); // NOLINT +const Event Event::AltN = Event::Special( + "\x1b" + "n"); // NOLINT +const Event Event::AltO = Event::Special( + "\x1b" + "o"); // NOLINT +const Event Event::AltP = Event::Special( + "\x1b" + "p"); // NOLINT +const Event Event::AltQ = Event::Special( + "\x1b" + "q"); // NOLINT +const Event Event::AltR = Event::Special( + "\x1b" + "r"); // NOLINT +const Event Event::AltS = Event::Special( + "\x1b" + "s"); // NOLINT +const Event Event::AltT = Event::Special( + "\x1b" + "t"); // NOLINT +const Event Event::AltU = Event::Special( + "\x1b" + "u"); // NOLINT +const Event Event::AltV = Event::Special( + "\x1b" + "v"); // NOLINT +const Event Event::AltW = Event::Special( + "\x1b" + "w"); // NOLINT +const Event Event::AltX = Event::Special( + "\x1b" + "x"); // NOLINT +const Event Event::AltY = Event::Special( + "\x1b" + "y"); // NOLINT +const Event Event::AltZ = Event::Special( + "\x1b" + "z"); // NOLINT -const Event Event::CtrlAltA = Event::Special("\x1b\x01"); // NOLINT -const Event Event::CtrlAltB = Event::Special("\x1b\x02"); // NOLINT -const Event Event::CtrlAltC = Event::Special("\x1b\x03"); // NOLINT -const Event Event::CtrlAltD = Event::Special("\x1b\x04"); // NOLINT -const Event Event::CtrlAltE = Event::Special("\x1b\x05"); // NOLINT -const Event Event::CtrlAltF = Event::Special("\x1b\x06"); // NOLINT -const Event Event::CtrlAltG = Event::Special("\x1b\x07"); // NOLINT -const Event Event::CtrlAltH = Event::Special("\x1b\x08"); // NOLINT -const Event Event::CtrlAltI = Event::Special("\x1b\x09"); // NOLINT -const Event Event::CtrlAltJ = Event::Special("\x1b\x0a"); // NOLINT -const Event Event::CtrlAltK = Event::Special("\x1b\x0b"); // NOLINT -const Event Event::CtrlAltL = Event::Special("\x1b\x0c"); // NOLINT -const Event Event::CtrlAltM = Event::Special("\x1b\x0d"); // NOLINT -const Event Event::CtrlAltN = Event::Special("\x1b\x0e"); // NOLINT -const Event Event::CtrlAltO = Event::Special("\x1b\x0f"); // NOLINT -const Event Event::CtrlAltP = Event::Special("\x1b\x10"); // NOLINT -const Event Event::CtrlAltQ = Event::Special("\x1b\x11"); // NOLINT -const Event Event::CtrlAltR = Event::Special("\x1b\x12"); // NOLINT -const Event Event::CtrlAltS = Event::Special("\x1b\x13"); // NOLINT -const Event Event::CtrlAltT = Event::Special("\x1b\x14"); // NOLINT -const Event Event::CtrlAltU = Event::Special("\x1b\x15"); // NOLINT -const Event Event::CtrlAltV = Event::Special("\x1b\x16"); // NOLINT -const Event Event::CtrlAltW = Event::Special("\x1b\x17"); // NOLINT -const Event Event::CtrlAltX = Event::Special("\x1b\x18"); // NOLINT -const Event Event::CtrlAltY = Event::Special("\x1b\x19"); // NOLINT -const Event Event::CtrlAltZ = Event::Special("\x1b\x1a"); // NOLINT +const Event Event::CtrlAltA = Event::Special("\x1b\x01"); // NOLINT +const Event Event::CtrlAltB = Event::Special("\x1b\x02"); // NOLINT +const Event Event::CtrlAltC = Event::Special("\x1b\x03"); // NOLINT +const Event Event::CtrlAltD = Event::Special("\x1b\x04"); // NOLINT +const Event Event::CtrlAltE = Event::Special("\x1b\x05"); // NOLINT +const Event Event::CtrlAltF = Event::Special("\x1b\x06"); // NOLINT +const Event Event::CtrlAltG = Event::Special("\x1b\x07"); // NOLINT +const Event Event::CtrlAltH = Event::Special("\x1b\x08"); // NOLINT +const Event Event::CtrlAltI = Event::Special("\x1b\x09"); // NOLINT +const Event Event::CtrlAltJ = Event::Special("\x1b\x0a"); // NOLINT +const Event Event::CtrlAltK = Event::Special("\x1b\x0b"); // NOLINT +const Event Event::CtrlAltL = Event::Special("\x1b\x0c"); // NOLINT +const Event Event::CtrlAltM = Event::Special("\x1b\x0d"); // NOLINT +const Event Event::CtrlAltN = Event::Special("\x1b\x0e"); // NOLINT +const Event Event::CtrlAltO = Event::Special("\x1b\x0f"); // NOLINT +const Event Event::CtrlAltP = Event::Special("\x1b\x10"); // NOLINT +const Event Event::CtrlAltQ = Event::Special("\x1b\x11"); // NOLINT +const Event Event::CtrlAltR = Event::Special("\x1b\x12"); // NOLINT +const Event Event::CtrlAltS = Event::Special("\x1b\x13"); // NOLINT +const Event Event::CtrlAltT = Event::Special("\x1b\x14"); // NOLINT +const Event Event::CtrlAltU = Event::Special("\x1b\x15"); // NOLINT +const Event Event::CtrlAltV = Event::Special("\x1b\x16"); // NOLINT +const Event Event::CtrlAltW = Event::Special("\x1b\x17"); // NOLINT +const Event Event::CtrlAltX = Event::Special("\x1b\x18"); // NOLINT +const Event Event::CtrlAltY = Event::Special("\x1b\x19"); // NOLINT +const Event Event::CtrlAltZ = Event::Special("\x1b\x1a"); // NOLINT } // namespace ftxui diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 320d6787..5cbe67f8 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -559,7 +559,6 @@ Closure ScreenInteractive::WithRestoredIO(Closure fn) { // NOLINT }; } - /// @brief Force FTXUI to handle or not handle Ctrl-C, even if the component /// catches the Event::CtrlC. void ScreenInteractive::ForceHandleCtrlC(bool force) { @@ -580,7 +579,6 @@ ScreenInteractive* ScreenInteractive::Active() { // private void ScreenInteractive::Install() { - frame_valid_ = false; // Flush the buffer for stdout to ensure whatever the user has printed before @@ -672,9 +670,9 @@ void ScreenInteractive::Install() { terminal.c_lflag &= ~IEXTEN; // Disable extended input processing terminal.c_cflag |= CS8; // 8 bits per byte - terminal.c_cc[VMIN] = 0; // Minimum number of characters for non-canonical - // read. - terminal.c_cc[VTIME] = 0; // Timeout in deciseconds for non-canonical read. + terminal.c_cc[VMIN] = 0; // Minimum number of characters for non-canonical + // read. + terminal.c_cc[VTIME] = 0; // Timeout in deciseconds for non-canonical read. tcsetattr(STDIN_FILENO, TCSANOW, &terminal); diff --git a/src/ftxui/component/terminal_input_parser.cpp b/src/ftxui/component/terminal_input_parser.cpp index d93ba49a..f07afa97 100644 --- a/src/ftxui/component/terminal_input_parser.cpp +++ b/src/ftxui/component/terminal_input_parser.cpp @@ -169,7 +169,7 @@ TerminalInputParser::Output TerminalInputParser::Parse() { if (!Eat()) { return UNCOMPLETED; } - + if (Current() == '\x1B') { return ParseESC(); } @@ -285,8 +285,7 @@ TerminalInputParser::Output TerminalInputParser::ParseESC() { case '*': case '+': case 'O': - case 'N': - { + case 'N': { if (!Eat()) { return UNCOMPLETED; } diff --git a/src/ftxui/component/terminal_input_parser_test.cpp b/src/ftxui/component/terminal_input_parser_test.cpp index 925b9697..ae60ff7d 100644 --- a/src/ftxui/component/terminal_input_parser_test.cpp +++ b/src/ftxui/component/terminal_input_parser_test.cpp @@ -353,8 +353,8 @@ TEST(Event, Control) { continue; cases.push_back({char(i), false}); } - cases.push_back({char(24), true}); - cases.push_back({char(26), true}); + cases.push_back({char(24), false}); + cases.push_back({char(26), false}); cases.push_back({char(127), false}); for (auto test : cases) { @@ -386,12 +386,9 @@ TEST(Event, Special) { Event expected; } kTestCase[] = { // Arrow (default cursor mode) - {str("\x1B[A"), Event::ArrowUp}, - {str("\x1B[B"), Event::ArrowDown}, - {str("\x1B[C"), Event::ArrowRight}, - {str("\x1B[D"), Event::ArrowLeft}, - {str("\x1B[H"), Event::Home}, - {str("\x1B[F"), Event::End}, + {str("\x1B[A"), Event::ArrowUp}, {str("\x1B[B"), Event::ArrowDown}, + {str("\x1B[C"), Event::ArrowRight}, {str("\x1B[D"), Event::ArrowLeft}, + {str("\x1B[H"), Event::Home}, {str("\x1B[F"), Event::End}, /* // Arrow (application cursor mode) diff --git a/src/ftxui/dom/canvas.cpp b/src/ftxui/dom/canvas.cpp index 81d415b0..8bf20513 100644 --- a/src/ftxui/dom/canvas.cpp +++ b/src/ftxui/dom/canvas.cpp @@ -828,7 +828,7 @@ void Canvas::DrawPixel(int x, int y, const Pixel& p) { } /// @brief Draw a predefined image, with top-left corner at the given coordinate -/// You can supply negative coordinates to align the image however you like - +/// You can supply negative coordinates to align the image however you like - /// only the 'visible' portion will be drawn /// @param x the x coordinate corresponding to the top-left corner of the image. /// @param y the y coordinate corresponding to the top-left corner of the image. diff --git a/src/ftxui/screen/image.cpp b/src/ftxui/screen/image.cpp index adee91b2..4df80fd2 100644 --- a/src/ftxui/screen/image.cpp +++ b/src/ftxui/screen/image.cpp @@ -10,17 +10,16 @@ #include // for pair #include "ftxui/screen/image.hpp" -#include "ftxui/screen/string.hpp" // for string_width +#include "ftxui/screen/string.hpp" // for string_width namespace ftxui { -namespace -{ - Pixel& dev_null_pixel() { - static Pixel pixel; - return pixel; - } +namespace { +Pixel& dev_null_pixel() { + static Pixel pixel; + return pixel; } +} // namespace Image::Image(int dimx, int dimy) : stencil{0, dimx - 1, 0, dimy - 1}, diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index 981a3f62..28ee7671 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -391,9 +391,9 @@ Screen::Screen(int dimx, int dimy) : Image{dimx, dimy} { #if defined(_WIN32) // The placement of this call is a bit weird, however we can assume that // anybody who instantiates a Screen object eventually wants to output - // something to the console. If that is not the case, use an instance of Image instead. - // As we require UTF8 for all input/output operations we will just switch to - // UTF8 encoding here + // something to the console. If that is not the case, use an instance of Image + // instead. As we require UTF8 for all input/output operations we will just + // switch to UTF8 encoding here SetConsoleOutputCP(CP_UTF8); SetConsoleCP(CP_UTF8); WindowsEmulateVT100Terminal();