Refactor tui related code

This commit is contained in:
SM9CC 2021-11-28 18:27:18 +00:00
parent bc4f3c2dd0
commit 7c1aa8e473
No known key found for this signature in database
GPG Key ID: 497769F3F5AD3A35
4 changed files with 64 additions and 49 deletions

View File

@ -58,7 +58,7 @@ add_executable(${PROJECT_NAME}
src/definitions.hpp
src/utils.cpp src/utils.hpp
src/main.cpp
)
src/tui.cpp src/tui.hpp)
# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
add_library(project_warnings INTERFACE)

View File

@ -1,17 +1,9 @@
#include "definitions.hpp"
#include "tui.hpp"
#include "utils.hpp"
#include <regex>
#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/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
using namespace ftxui;
int main() {
const auto& tty = utils::exec("tty");
const std::regex tty_regex("/dev/tty[0-9]*");
@ -34,43 +26,5 @@ int main() {
return 0;
}
auto screen = ScreenInteractive::Fullscreen();
auto button_ok = Button("Ok", screen.ExitLoopClosure());
auto button_quit = Button("Quit", screen.ExitLoopClosure());
auto component = Container::Horizontal({
button_ok,
button_quit,
});
auto dialog = vbox({
text("TODO!!"),
separator(),
hbox({
button_ok->Render(),
button_quit->Render(),
}),
});
// -------- Center Menu --------------
/* clang-format off */
auto center_dialog = hbox({
filler(),
border(dialog),
filler(),
}) | vcenter;
/* clang-format on */
auto renderer = Renderer(component, [&] {
return vbox({
text("New CLI Installer") | bold,
filler(),
// -------- Center Menu --------------
center_dialog | hcenter,
filler(),
});
});
screen.Loop(renderer);
tui::init();
}

53
src/tui.cpp Normal file
View File

@ -0,0 +1,53 @@
#include "tui.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/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>
using namespace ftxui;
namespace tui {
void init() noexcept {
auto screen = ScreenInteractive::Fullscreen();
auto button_ok = Button("Ok", screen.ExitLoopClosure());
auto button_quit = Button("Quit", screen.ExitLoopClosure());
auto component = Container::Horizontal({
button_ok,
button_quit,
});
auto dialog = vbox({
text("TODO!!"),
separator(),
hbox({
button_ok->Render(),
button_quit->Render(),
}),
});
// -------- Center Menu --------------
/* clang-format off */
auto center_dialog = hbox({
filler(),
border(dialog),
filler(),
}) | vcenter;
/* clang-format on */
auto renderer = Renderer(component, [&] {
return vbox({
text("New CLI Installer") | bold,
filler(),
// -------- Center Menu --------------
center_dialog | hcenter,
filler(),
});
});
screen.Loop(renderer);
}
} // namespace tui

8
src/tui.hpp Normal file
View File

@ -0,0 +1,8 @@
#ifndef TUI_HPP
#define TUI_HPP
namespace tui {
void init() noexcept;
} // namespace tui
#endif // TUI_HPP