From 7c1aa8e47317b09bcecec0271c62cb8714fa03a9 Mon Sep 17 00:00:00 2001 From: SM9CC Date: Sun, 28 Nov 2021 18:27:18 +0000 Subject: [PATCH] Refactor tui related code --- CMakeLists.txt | 2 +- src/main.cpp | 50 ++--------------------------------------------- src/tui.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/tui.hpp | 8 ++++++++ 4 files changed, 64 insertions(+), 49 deletions(-) create mode 100644 src/tui.cpp create mode 100644 src/tui.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 79ddcb6..16cf3d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/main.cpp b/src/main.cpp index 6999fbc..2889a10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,17 +1,9 @@ #include "definitions.hpp" +#include "tui.hpp" #include "utils.hpp" #include -#include -#include -#include -#include -#include -#include - -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(); } diff --git a/src/tui.cpp b/src/tui.cpp new file mode 100644 index 0000000..3bc9dbb --- /dev/null +++ b/src/tui.cpp @@ -0,0 +1,53 @@ +#include "tui.hpp" +#include +#include +#include +#include +#include +#include + +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 diff --git a/src/tui.hpp b/src/tui.hpp new file mode 100644 index 0000000..e9df554 --- /dev/null +++ b/src/tui.hpp @@ -0,0 +1,8 @@ +#ifndef TUI_HPP +#define TUI_HPP + +namespace tui { +void init() noexcept; +} // namespace tui + +#endif // TUI_HPP