From 36c3bb36687524d3bb86d286b6787e1878e460d7 Mon Sep 17 00:00:00 2001 From: ohyzha Date: Tue, 17 Dec 2024 11:45:29 +0200 Subject: [PATCH] add CtrlC and CtrlZ events handling --- examples/main.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/main.cpp b/examples/main.cpp index 002e431..8ac6541 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -11,6 +11,7 @@ #include #include #include +#include // for Event, Event::Custom #include #include @@ -28,9 +29,21 @@ int main(int argc, char** argv) int selectedExample = 0; ftxui::MenuOption option; auto screen = ftxui::ScreenInteractive::TerminalOutput(); + screen.ForceHandleCtrlC(true); + //screen.ForceHandleCtrlZ(true); option.on_enter = screen.ExitLoopClosure(); 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); if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!");