Merge pull request 'Add handlers to exit ftxui console menu' (#175) from misc into master
Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/175 Reviewed-by: Georg Hagen <georg.hagen@madvoxel.com>
This commit is contained in:
2
3rdParty/ftxui/CMakeLists.txt
vendored
2
3rdParty/ftxui/CMakeLists.txt
vendored
@@ -8,7 +8,7 @@ FetchContent_Declare(
|
|||||||
ftxui
|
ftxui
|
||||||
EXCLUDE_FROM_ALL
|
EXCLUDE_FROM_ALL
|
||||||
GIT_REPOSITORY ${FTXUI_REPO}
|
GIT_REPOSITORY ${FTXUI_REPO}
|
||||||
GIT_TAG v5.0.0
|
GIT_TAG daa421fa6ad97c8a6c9bd43f77c81862bfa52c77
|
||||||
GIT_SHALLOW TRUE
|
GIT_SHALLOW TRUE
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(ftxui)
|
FetchContent_MakeAvailable(ftxui)
|
||||||
@@ -35,7 +35,6 @@ namespace OpenVulkano
|
|||||||
void Init() override
|
void Init() override
|
||||||
{
|
{
|
||||||
auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
|
auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
|
||||||
engineConfig->SetNumThreads(4);
|
|
||||||
engineConfig->SetPreferFramebufferFormatSRGB(false);
|
engineConfig->SetPreferFramebufferFormatSRGB(false);
|
||||||
engineConfig->SetFpsCap(0); // monitor's refresh rate
|
engineConfig->SetFpsCap(0); // monitor's refresh rate
|
||||||
engineConfig->SetVSync(true);
|
engineConfig->SetVSync(true);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace OpenVulkano
|
|||||||
void Init() override
|
void Init() override
|
||||||
{
|
{
|
||||||
auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
|
auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
|
||||||
engineConfig->SetNumThreads(4);
|
//engineConfig->SetNumThreads(4);
|
||||||
engineConfig->SetPreferFramebufferFormatSRGB(false);
|
engineConfig->SetPreferFramebufferFormatSRGB(false);
|
||||||
|
|
||||||
std::srand(1); // Fix seed for random numbers
|
std::srand(1); // Fix seed for random numbers
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ namespace OpenVulkano
|
|||||||
void Init() override
|
void Init() override
|
||||||
{
|
{
|
||||||
auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
|
auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
|
||||||
engineConfig->SetNumThreads(4);
|
|
||||||
engineConfig->SetPreferFramebufferFormatSRGB(false);
|
engineConfig->SetPreferFramebufferFormatSRGB(false);
|
||||||
|
|
||||||
std::srand(1); // Fix seed for random numbers
|
std::srand(1); // Fix seed for random numbers
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <ftxui/component/component.hpp>
|
#include <ftxui/component/component.hpp>
|
||||||
#include <ftxui/component/component_options.hpp>
|
#include <ftxui/component/component_options.hpp>
|
||||||
#include <ftxui/component/screen_interactive.hpp>
|
#include <ftxui/component/screen_interactive.hpp>
|
||||||
|
#include <ftxui/component/event.hpp> // for Event, Event::Custom
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -28,14 +29,34 @@ int main(int argc, char** argv)
|
|||||||
int selectedExample = 0;
|
int selectedExample = 0;
|
||||||
ftxui::MenuOption option;
|
ftxui::MenuOption option;
|
||||||
auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
auto screen = ftxui::ScreenInteractive::TerminalOutput();
|
||||||
|
screen.ForceHandleCtrlC(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 shouldExit = false;
|
||||||
|
menu |= ftxui::CatchEvent(
|
||||||
|
[&](ftxui::Event event)
|
||||||
|
{
|
||||||
|
if (event == ftxui::Event::CtrlC || event == ftxui::Event::CtrlZ)
|
||||||
|
{
|
||||||
|
screen.ExitLoopClosure()();
|
||||||
|
shouldExit = true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
screen.Loop(menu);
|
screen.Loop(menu);
|
||||||
|
|
||||||
if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!");
|
if (shouldExit)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<IGraphicsApp> app( EXAMPLE_APPS[selectedExample].second() );
|
if (selectedExample >= examples.size())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Invalid menu selection!");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<IGraphicsApp> app(EXAMPLE_APPS[selectedExample].second());
|
||||||
|
|
||||||
GraphicsAppManager manager(app.get());
|
GraphicsAppManager manager(app.get());
|
||||||
manager.Run();
|
manager.Run();
|
||||||
|
|||||||
Reference in New Issue
Block a user