63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "Host/GraphicsAppManager.hpp"
|
|
#include "ExampleAppList.hpp"
|
|
|
|
#include <ftxui/component/captured_mouse.hpp>
|
|
#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>
|
|
|
|
using namespace OpenVulkano;
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
std::vector<std::string> examples;
|
|
for (const auto& e : EXAMPLE_APPS)
|
|
{
|
|
examples.emplace_back(e.first);
|
|
}
|
|
|
|
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 emergencyExit = false;
|
|
menu |= ftxui::CatchEvent(
|
|
[&](ftxui::Event event)
|
|
{
|
|
if (event == ftxui::Event::CtrlC || event == ftxui::Event::CtrlZ)
|
|
{
|
|
screen.ExitLoopClosure()();
|
|
emergencyExit = true;
|
|
}
|
|
return false;
|
|
});
|
|
screen.Loop(menu);
|
|
|
|
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;
|
|
}
|