From e9ec896feef351396a947fa3ecd8606c8c8fd156 Mon Sep 17 00:00:00 2001 From: ohyzha Date: Tue, 17 Dec 2024 13:25:25 +0200 Subject: [PATCH] refactoring --- examples/main.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/main.cpp b/examples/main.cpp index e0a35b7..f10b998 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -33,30 +33,32 @@ int main(int argc, char** argv) //screen.ForceHandleCtrlZ(true); option.on_enter = screen.ExitLoopClosure(); auto menu = ftxui::Menu(&examples, &selectedExample, option); - bool emergencyExit = false; + bool shouldExit = false; menu |= ftxui::CatchEvent( [&](ftxui::Event event) { if (event == ftxui::Event::CtrlC || event == ftxui::Event::CtrlZ) { screen.ExitLoopClosure()(); - emergencyExit = true; + shouldExit = true; } return false; }); screen.Loop(menu); - if (!emergencyExit) + if (shouldExit) { - if (selectedExample >= examples.size()) - { - throw std::runtime_error("Invalid menu selection!"); - } - - std::unique_ptr app(EXAMPLE_APPS[selectedExample].second()); - - GraphicsAppManager manager(app.get()); - manager.Run(); + return 0; } + + if (selectedExample >= examples.size()) + { + throw std::runtime_error("Invalid menu selection!"); + } + + std::unique_ptr app(EXAMPLE_APPS[selectedExample].second()); + + GraphicsAppManager manager(app.get()); + manager.Run(); return 0; }