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:
Oleksii_Hyzha
2024-12-17 13:18:03 +01:00
5 changed files with 26 additions and 7 deletions

View File

@@ -8,7 +8,7 @@ FetchContent_Declare(
ftxui
EXCLUDE_FROM_ALL
GIT_REPOSITORY ${FTXUI_REPO}
GIT_TAG v5.0.0
GIT_TAG daa421fa6ad97c8a6c9bd43f77c81862bfa52c77
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(ftxui)

View File

@@ -35,7 +35,6 @@ namespace OpenVulkano
void Init() override
{
auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
engineConfig->SetNumThreads(4);
engineConfig->SetPreferFramebufferFormatSRGB(false);
engineConfig->SetFpsCap(0); // monitor's refresh rate
engineConfig->SetVSync(true);

View File

@@ -51,7 +51,7 @@ namespace OpenVulkano
void Init() override
{
auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
engineConfig->SetNumThreads(4);
//engineConfig->SetNumThreads(4);
engineConfig->SetPreferFramebufferFormatSRGB(false);
std::srand(1); // Fix seed for random numbers

View File

@@ -47,7 +47,6 @@ namespace OpenVulkano
void Init() override
{
auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
engineConfig->SetNumThreads(4);
engineConfig->SetPreferFramebufferFormatSRGB(false);
std::srand(1); // Fix seed for random numbers

View File

@@ -11,6 +11,7 @@
#include <ftxui/component/component.hpp>
#include <ftxui/component/component_options.hpp>
#include <ftxui/component/screen_interactive.hpp>
#include <ftxui/component/event.hpp> // for Event, Event::Custom
#include <vector>
#include <string>
@@ -28,12 +29,32 @@ int main(int argc, char** argv)
int selectedExample = 0;
ftxui::MenuOption option;
auto screen = ftxui::ScreenInteractive::TerminalOutput();
screen.ForceHandleCtrlC(true);
//screen.ForceHandleCtrlZ(true);
option.on_enter = screen.ExitLoopClosure();
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);
if (selectedExample >= examples.size()) throw std::runtime_error("Invalid menu selection!");
if (shouldExit)
{
return 0;
}
if (selectedExample >= examples.size())
{
throw std::runtime_error("Invalid menu selection!");
}
std::unique_ptr<IGraphicsApp> app(EXAMPLE_APPS[selectedExample].second());