Skip to content

Commit b78e637

Browse files
committed
Basic FTXUI working
1 parent e513bb8 commit b78e637

File tree

3 files changed

+79
-20
lines changed

3 files changed

+79
-20
lines changed

CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ set(CMAKE_CXX_STANDARD 20)
99
# when compiling with PCH enabled
1010
set(CMAKE_CXX_EXTENSIONS OFF)
1111

12+
include(FetchContent)
13+
14+
set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
15+
FetchContent_Declare(ftxui
16+
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
17+
GIT_TAG v2.0.0
18+
)
19+
20+
FetchContent_GetProperties(ftxui)
21+
if(NOT ftxui_POPULATED)
22+
FetchContent_Populate(ftxui)
23+
add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
24+
endif()
25+
26+
27+
1228
# Note: by default ENABLE_DEVELOPER_MODE is True
1329
# This means that all analysis (sanitizers, static analysis)
1430
# is enabled and all warnings are treated as errors
@@ -22,7 +38,6 @@ set(OPT_WARNINGS_AS_ERRORS_DEVELOPER_DEFAULT TRUE)
2238

2339
# Add project_options v0.17.0
2440
# https://github.com/cpp-best-practices/project_options
25-
include(FetchContent)
2641
FetchContent_Declare(_project_options
2742
URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.17.0.zip)
2843
FetchContent_MakeAvailable(_project_options)

src/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ target_link_libraries(
1212
fmt::fmt
1313
spdlog::spdlog)
1414

15-
target_include_directories(intro PRIVATE "${CMAKE_BINARY_DIR}/configured_files/include")
15+
target_link_system_libraries(
16+
intro
17+
PRIVATE
18+
ftxui::screen
19+
ftxui::dom
20+
ftxui::component)
1621

22+
target_include_directories(intro PRIVATE "${CMAKE_BINARY_DIR}/configured_files/include")

src/main.cpp

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,26 @@
22
#include <iostream>
33

44
#include <docopt/docopt.h>
5+
#include <ftxui/component/captured_mouse.hpp>// for ftxui
6+
#include <ftxui/component/component.hpp>// for Slider
7+
#include <ftxui/component/screen_interactive.hpp>// for ScreenInteractive
58
#include <spdlog/spdlog.h>
69

7-
// This file will be generated automatically when you run the CMake configuration step.
8-
// It creates a namespace called `myproject`.
9-
// You can modify the source template at `configured_files/config.hpp.in`.
10+
// This file will be generated automatically when you run the CMake
11+
// configuration step. It creates a namespace called `myproject`. You can modify
12+
// the source template at `configured_files/config.hpp.in`.
1013
#include <internal_use_only/config.hpp>
1114

1215
static constexpr auto USAGE =
13-
R"(Naval Fate.
16+
R"(intro
1417
1518
Usage:
16-
naval_fate ship new <name>...
17-
naval_fate ship <name> move <x> <y> [--speed=<kn>]
18-
naval_fate ship shoot <x> <y>
19-
naval_fate mine (set|remove) <x> <y> [--moored | --drifting]
20-
naval_fate (-h | --help)
21-
naval_fate --version
19+
intro
20+
intro (-h | --help)
21+
intro --version
2222
Options:
2323
-h --help Show this screen.
2424
--version Show version.
25-
--speed=<kn> Speed in knots [default: 10].
26-
--moored Moored (anchored) mine.
27-
--drifting Drifting mine.
2825
)";
2926

3027
int main(int argc, const char **argv)
@@ -35,15 +32,56 @@ int main(int argc, const char **argv)
3532
true,// show help if requested
3633
fmt::format("{} {}",
3734
myproject::cmake::project_name,
38-
myproject::cmake::project_version));// version string, acquired from config.hpp via CMake
35+
myproject::cmake::project_version));// version string, acquired
36+
// from config.hpp via CMake
3937

40-
for (auto const &arg : args) { std::cout << arg.first << "=" << arg.second << '\n'; }
38+
using namespace ftxui;
39+
std::vector<std::string> toggle_1_entries = {
40+
"On",
41+
"Off",
42+
};
43+
std::vector<std::string> toggle_2_entries = {
44+
"Enabled",
45+
"Disabled",
46+
};
47+
std::vector<std::string> toggle_3_entries = {
48+
"10€",
49+
"0€",
50+
};
51+
std::vector<std::string> toggle_4_entries = {
52+
"Nothing",
53+
"One element",
54+
"Several elements",
55+
};
4156

57+
auto screen = ScreenInteractive::TerminalOutput();
4258

43-
// Use the default logger (stdout, multi-threaded, colored)
44-
spdlog::info("Hello, {}!", "World");
59+
int toggle_1_selected = 0;
60+
int toggle_2_selected = 0;
61+
int toggle_3_selected = 0;
62+
int toggle_4_selected = 0;
63+
Component toggle_1 = Toggle(&toggle_1_entries, &toggle_1_selected);
64+
Component toggle_2 = Toggle(&toggle_2_entries, &toggle_2_selected);
65+
Component toggle_3 = Toggle(&toggle_3_entries, &toggle_3_selected);
66+
Component toggle_4 = Toggle(&toggle_4_entries, &toggle_4_selected);
67+
auto quit_button = Button("Save & Quit", screen.ExitLoopClosure());
68+
69+
auto container = Container::Vertical({ toggle_1, toggle_2, toggle_3, toggle_4, quit_button });
70+
71+
auto renderer = Renderer(container, [&] {
72+
return vbox({ text("Choose your options:"),
73+
text(""),
74+
hbox(text(" * Poweroff on startup : "), toggle_1->Render()),
75+
hbox(text(" * Out of process : "), toggle_2->Render()),
76+
hbox(text(" * Price of the information : "), toggle_3->Render()),
77+
hbox(text(" * Number of elements : "), toggle_4->Render()),
78+
text(""),
79+
hbox(toggle_1_selected == 0 ? color(Color::Green, quit_button->Render())
80+
: color(Color::Blue, quit_button->Render())) });
81+
});
82+
83+
screen.Loop(renderer);
4584

46-
fmt::print("Hello, from {}\n", "{fmt}");
4785
} catch (const std::exception &e) {
4886
fmt::print("Unhandled exception in main: {}", e.what());
4987
}

0 commit comments

Comments
 (0)