add CtrlC and CtrlZ events handling
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include <ftxui/component/component.hpp>
|
#include <ftxui/component/component.hpp>
|
||||||
#include <ftxui/component/component_options.hpp>
|
#include <ftxui/component/component_options.hpp>
|
||||||
#include <ftxui/component/screen_interactive.hpp>
|
#include <ftxui/component/screen_interactive.hpp>
|
||||||
|
#include <ftxui/component/event.hpp> // for Event, Event::Custom
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -28,9 +29,21 @@ int main(int argc, char** argv)
|
|||||||
int selectedExample = 0;
|
int selectedExample = 0;
|
||||||
ftxui::MenuOption option;
|
ftxui::MenuOption option;
|
||||||
auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
||||||
|
screen.ForceHandleCtrlC(true);
|
||||||
|
//screen.ForceHandleCtrlZ(true);
|
||||||
option.on_enter = screen.ExitLoopClosure();
|
option.on_enter = screen.ExitLoopClosure();
|
||||||
auto menu = ftxui::Menu(&examples, &selectedExample, option);
|
auto menu = ftxui::Menu(&examples, &selectedExample, option);
|
||||||
|
|
||||||
|
menu |= ftxui::CatchEvent(
|
||||||
|
[&](ftxui::Event event)
|
||||||
|
{
|
||||||
|
if (event == ftxui::Event::CtrlC || event == ftxui::Event::CtrlZ)
|
||||||
|
{
|
||||||
|
screen.ExitLoopClosure()();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
screen.Loop(menu);
|
screen.Loop(menu);
|
||||||
|
|
||||||
if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!");
|
if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!");
|
||||||
|
|||||||
Reference in New Issue
Block a user