Fix Event.Control test.

This commit is contained in:
ArthurSonzogni 2024-04-27 20:49:49 +02:00
parent 2b73998d56
commit 092482f63b
No known key found for this signature in database
GPG Key ID: 41D98248C074CD6C
11 changed files with 216 additions and 170 deletions

View File

@ -62,9 +62,9 @@ class ScreenInteractive : public Screen {
// 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 // are executed, even if the component catches the event. This avoid users
// handling every event to be trapped in the application. However, in some // 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, // cases, the application may want to handle these events itself. In this
// the application can force FTXUI to not handle these events by calling the // case, the application can force FTXUI to not handle these events by calling
// following functions with force=true. // the following functions with force=true.
void ForceHandleCtrlC(bool force); void ForceHandleCtrlC(bool force);
void ForceHandleCtrlZ(bool force); void ForceHandleCtrlZ(bool force);

View File

@ -36,7 +36,8 @@ class Screen : public Image {
// Print the Screen on to the terminal. // Print the Screen on to the terminal.
void Print() const; 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(); void Clear();
// Move the terminal cursor n-lines up with n = dimy(). // Move the terminal cursor n-lines up with n = dimy().

View File

@ -229,7 +229,7 @@ std::string Event::DebugString() const {
{Mouse::Motion::Moved, ".motion = Mouse::Moved"}, {Mouse::Motion::Moved, ".motion = Mouse::Moved"},
}; };
switch(type_) { switch (type_) {
case Type::Character: { case Type::Character: {
return "Event::Character(\"" + input_ + "\")"; return "Event::Character(\"" + input_ + "\")";
} }
@ -392,32 +392,84 @@ const Event Event::CtrlX = Event::Special("\x18"); // NOLINT
const Event Event::CtrlY = Event::Special("\x19"); // NOLINT const Event Event::CtrlY = Event::Special("\x19"); // NOLINT
const Event Event::CtrlZ = Event::Special("\x1a"); // NOLINT const Event Event::CtrlZ = Event::Special("\x1a"); // NOLINT
const Event Event::AltA = Event::Special("\x1b""a"); // NOLINT const Event Event::AltA = Event::Special(
const Event Event::AltB = Event::Special("\x1b""b"); // NOLINT "\x1b"
const Event Event::AltC = Event::Special("\x1b""c"); // NOLINT "a"); // NOLINT
const Event Event::AltD = Event::Special("\x1b""d"); // NOLINT const Event Event::AltB = Event::Special(
const Event Event::AltE = Event::Special("\x1b""e"); // NOLINT "\x1b"
const Event Event::AltF = Event::Special("\x1b""f"); // NOLINT "b"); // NOLINT
const Event Event::AltG = Event::Special("\x1b""g"); // NOLINT const Event Event::AltC = Event::Special(
const Event Event::AltH = Event::Special("\x1b""h"); // NOLINT "\x1b"
const Event Event::AltI = Event::Special("\x1b""i"); // NOLINT "c"); // NOLINT
const Event Event::AltJ = Event::Special("\x1b""j"); // NOLINT const Event Event::AltD = Event::Special(
const Event Event::AltK = Event::Special("\x1b""k"); // NOLINT "\x1b"
const Event Event::AltL = Event::Special("\x1b""l"); // NOLINT "d"); // NOLINT
const Event Event::AltM = Event::Special("\x1b""m"); // NOLINT const Event Event::AltE = Event::Special(
const Event Event::AltN = Event::Special("\x1b""n"); // NOLINT "\x1b"
const Event Event::AltO = Event::Special("\x1b""o"); // NOLINT "e"); // NOLINT
const Event Event::AltP = Event::Special("\x1b""p"); // NOLINT const Event Event::AltF = Event::Special(
const Event Event::AltQ = Event::Special("\x1b""q"); // NOLINT "\x1b"
const Event Event::AltR = Event::Special("\x1b""r"); // NOLINT "f"); // NOLINT
const Event Event::AltS = Event::Special("\x1b""s"); // NOLINT const Event Event::AltG = Event::Special(
const Event Event::AltT = Event::Special("\x1b""t"); // NOLINT "\x1b"
const Event Event::AltU = Event::Special("\x1b""u"); // NOLINT "g"); // NOLINT
const Event Event::AltV = Event::Special("\x1b""v"); // NOLINT const Event Event::AltH = Event::Special(
const Event Event::AltW = Event::Special("\x1b""w"); // NOLINT "\x1b"
const Event Event::AltX = Event::Special("\x1b""x"); // NOLINT "h"); // NOLINT
const Event Event::AltY = Event::Special("\x1b""y"); // NOLINT const Event Event::AltI = Event::Special(
const Event Event::AltZ = Event::Special("\x1b""z"); // NOLINT "\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::CtrlAltA = Event::Special("\x1b\x01"); // NOLINT
const Event Event::CtrlAltB = Event::Special("\x1b\x02"); // NOLINT const Event Event::CtrlAltB = Event::Special("\x1b\x02"); // NOLINT

View File

@ -559,7 +559,6 @@ Closure ScreenInteractive::WithRestoredIO(Closure fn) { // NOLINT
}; };
} }
/// @brief Force FTXUI to handle or not handle Ctrl-C, even if the component /// @brief Force FTXUI to handle or not handle Ctrl-C, even if the component
/// catches the Event::CtrlC. /// catches the Event::CtrlC.
void ScreenInteractive::ForceHandleCtrlC(bool force) { void ScreenInteractive::ForceHandleCtrlC(bool force) {
@ -580,7 +579,6 @@ ScreenInteractive* ScreenInteractive::Active() {
// private // private
void ScreenInteractive::Install() { void ScreenInteractive::Install() {
frame_valid_ = false; frame_valid_ = false;
// Flush the buffer for stdout to ensure whatever the user has printed before // Flush the buffer for stdout to ensure whatever the user has printed before

View File

@ -285,8 +285,7 @@ TerminalInputParser::Output TerminalInputParser::ParseESC() {
case '*': case '*':
case '+': case '+':
case 'O': case 'O':
case 'N': case 'N': {
{
if (!Eat()) { if (!Eat()) {
return UNCOMPLETED; return UNCOMPLETED;
} }

View File

@ -353,8 +353,8 @@ TEST(Event, Control) {
continue; continue;
cases.push_back({char(i), false}); cases.push_back({char(i), false});
} }
cases.push_back({char(24), true}); cases.push_back({char(24), false});
cases.push_back({char(26), true}); cases.push_back({char(26), false});
cases.push_back({char(127), false}); cases.push_back({char(127), false});
for (auto test : cases) { for (auto test : cases) {
@ -386,12 +386,9 @@ TEST(Event, Special) {
Event expected; Event expected;
} kTestCase[] = { } kTestCase[] = {
// Arrow (default cursor mode) // Arrow (default cursor mode)
{str("\x1B[A"), Event::ArrowUp}, {str("\x1B[A"), Event::ArrowUp}, {str("\x1B[B"), Event::ArrowDown},
{str("\x1B[B"), Event::ArrowDown}, {str("\x1B[C"), Event::ArrowRight}, {str("\x1B[D"), Event::ArrowLeft},
{str("\x1B[C"), Event::ArrowRight}, {str("\x1B[H"), Event::Home}, {str("\x1B[F"), Event::End},
{str("\x1B[D"), Event::ArrowLeft},
{str("\x1B[H"), Event::Home},
{str("\x1B[F"), Event::End},
/* /*
// Arrow (application cursor mode) // Arrow (application cursor mode)

View File

@ -14,13 +14,12 @@
namespace ftxui { namespace ftxui {
namespace namespace {
{ Pixel& dev_null_pixel() {
Pixel& dev_null_pixel() {
static Pixel pixel; static Pixel pixel;
return pixel; return pixel;
}
} }
} // namespace
Image::Image(int dimx, int dimy) Image::Image(int dimx, int dimy)
: stencil{0, dimx - 1, 0, dimy - 1}, : stencil{0, dimx - 1, 0, dimy - 1},

View File

@ -391,9 +391,9 @@ Screen::Screen(int dimx, int dimy) : Image{dimx, dimy} {
#if defined(_WIN32) #if defined(_WIN32)
// The placement of this call is a bit weird, however we can assume that // The placement of this call is a bit weird, however we can assume that
// anybody who instantiates a Screen object eventually wants to output // 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. // something to the console. If that is not the case, use an instance of Image
// As we require UTF8 for all input/output operations we will just switch to // instead. As we require UTF8 for all input/output operations we will just
// UTF8 encoding here // switch to UTF8 encoding here
SetConsoleOutputCP(CP_UTF8); SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8); SetConsoleCP(CP_UTF8);
WindowsEmulateVT100Terminal(); WindowsEmulateVT100Terminal();