introduce flag for emergency menu exit

This commit is contained in:
ohyzha
2024-12-17 13:07:23 +02:00
parent 36c3bb3668
commit ddded99bf7

View File

@@ -33,24 +33,30 @@ int main(int argc, char** argv)
//screen.ForceHandleCtrlZ(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);
bool emergencyExit = false;
menu |= ftxui::CatchEvent( menu |= ftxui::CatchEvent(
[&](ftxui::Event event) [&](ftxui::Event event)
{ {
if (event == ftxui::Event::CtrlC || event == ftxui::Event::CtrlZ) if (event == ftxui::Event::CtrlC || event == ftxui::Event::CtrlZ)
{ {
screen.ExitLoopClosure()(); screen.ExitLoopClosure()();
exit(0); emergencyExit = true;
} }
return false; return false;
}); });
screen.Loop(menu); screen.Loop(menu);
if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!"); if (!emergencyExit)
{
if (selectedExample >= examples.size())
{
throw std::runtime_error("Invalid menu selection!");
}
std::unique_ptr<IGraphicsApp> app( EXAMPLE_APPS[selectedExample].second() ); std::unique_ptr<IGraphicsApp> app(EXAMPLE_APPS[selectedExample].second());
GraphicsAppManager manager(app.get()); GraphicsAppManager manager(app.get());
manager.Run(); manager.Run();
}
return 0; return 0;
} }