introduce flag for emergency menu exit
This commit is contained in:
@@ -33,24 +33,30 @@ int main(int argc, char** argv)
|
||||
//screen.ForceHandleCtrlZ(true);
|
||||
option.on_enter = screen.ExitLoopClosure();
|
||||
auto menu = ftxui::Menu(&examples, &selectedExample, option);
|
||||
|
||||
bool emergencyExit = false;
|
||||
menu |= ftxui::CatchEvent(
|
||||
[&](ftxui::Event event)
|
||||
{
|
||||
if (event == ftxui::Event::CtrlC || event == ftxui::Event::CtrlZ)
|
||||
{
|
||||
screen.ExitLoopClosure()();
|
||||
exit(0);
|
||||
emergencyExit = true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
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());
|
||||
|
||||
GraphicsAppManager manager(app.get());
|
||||
manager.Run();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user