mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-06-25 09:01:11 +08:00
Fix Event.Control test.
This commit is contained in:
parent
2b73998d56
commit
092482f63b
@ -62,9 +62,9 @@ class ScreenInteractive : public Screen {
|
||||
// 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);
|
||||
|
||||
|
@ -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().
|
||||
|
@ -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_ + "\")";
|
||||
}
|
||||
@ -392,32 +392,84 @@ 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
|
||||
|
@ -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
|
||||
|
@ -285,8 +285,7 @@ TerminalInputParser::Output TerminalInputParser::ParseESC() {
|
||||
case '*':
|
||||
case '+':
|
||||
case 'O':
|
||||
case 'N':
|
||||
{
|
||||
case 'N': {
|
||||
if (!Eat()) {
|
||||
return UNCOMPLETED;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -14,13 +14,12 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
namespace
|
||||
{
|
||||
Pixel& dev_null_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},
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user