mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Enable raw keyboard input (#832)
In order for applications to receive all keyboard inputs, including the Ctrl-C and Ctrl-Z, the raw input mode has been enabled. As result the SIGINT will no longer be used, instead the keyboard Ctrl-C event is used for exiting the framework, but only if no components has made use of it. Co-authored-by: Jørn Gustav Larsen <jgl@fasttracksoftware.com> Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
committed by
GitHub
parent
d38b14ffb6
commit
d386df6f94
@@ -64,4 +64,71 @@ TEST(ScreenInteractive, PostTaskToNonActive) {
|
||||
screen.Post([] {});
|
||||
}
|
||||
|
||||
TEST(ScreenInteractive, CtrlC) {
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
bool called = false;
|
||||
auto component = Renderer([&] {
|
||||
if (!called) {
|
||||
called = true;
|
||||
screen.PostEvent(Event::CtrlC);
|
||||
}
|
||||
return text("");
|
||||
});
|
||||
screen.Loop(component);
|
||||
}
|
||||
|
||||
TEST(ScreenInteractive, CtrlC_Forced) {
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.ForceHandleCtrlC(true);
|
||||
auto component = Renderer([&] {
|
||||
screen.PostEvent(Event::CtrlC);
|
||||
return text("");
|
||||
});
|
||||
|
||||
int ctrl_c_count = 0;
|
||||
component |= CatchEvent([&](Event event) {
|
||||
if (event != Event::CtrlC) {
|
||||
return false;
|
||||
}
|
||||
|
||||
++ctrl_c_count;
|
||||
|
||||
if (ctrl_c_count == 100) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
screen.Loop(component);
|
||||
|
||||
ASSERT_LE(ctrl_c_count, 50);
|
||||
}
|
||||
|
||||
TEST(ScreenInteractive, CtrlC_NotForced) {
|
||||
auto screen = ScreenInteractive::FitComponent();
|
||||
screen.ForceHandleCtrlC(false);
|
||||
auto component = Renderer([&] {
|
||||
screen.PostEvent(Event::CtrlC);
|
||||
return text("");
|
||||
});
|
||||
|
||||
int ctrl_c_count = 0;
|
||||
component |= CatchEvent([&](Event event) {
|
||||
if (event != Event::CtrlC) {
|
||||
return false;
|
||||
}
|
||||
|
||||
++ctrl_c_count;
|
||||
|
||||
if (ctrl_c_count == 100) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
screen.Loop(component);
|
||||
|
||||
ASSERT_GE(ctrl_c_count, 50);
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
Reference in New Issue
Block a user