refactoring

This commit is contained in:
ohyzha
2024-12-17 13:25:25 +02:00
parent ddded99bf7
commit e9ec896fee

View File

@@ -33,30 +33,32 @@ 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; bool shouldExit = 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()();
emergencyExit = true; shouldExit = true;
} }
return false; return false;
}); });
screen.Loop(menu); screen.Loop(menu);
if (!emergencyExit) if (shouldExit)
{ {
if (selectedExample >= examples.size()) return 0;
{
throw std::runtime_error("Invalid menu selection!");
}
std::unique_ptr<IGraphicsApp> app(EXAMPLE_APPS[selectedExample].second());
GraphicsAppManager manager(app.get());
manager.Run();
} }
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; return 0;
} }