Skip to content

Commit

Permalink
Add fxtui example
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolasan committed Oct 22, 2024
1 parent f937d89 commit d810713
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
34 changes: 33 additions & 1 deletion cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@

include_directories(thirdparty)
add_executable(cryptor cryptor.cpp)
add_executable(cryptor cryptor.cpp)

include(FetchContent)

FetchContent_Declare(ftxui
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
GIT_TAG v5.0.0
GIT_PROGRESS TRUE
GIT_SHALLOW FALSE
EXCLUDE_FROM_ALL
FIND_PACKAGE_ARGS NAMES ftxui
)

FetchContent_Declare(nlohmann_json
URL https://github.com/nlohmann/json/releases/download/v3.10.5/json.tar.xz
EXCLUDE_FROM_ALL
FIND_PACKAGE_ARGS NAMES nlohmann_json
)

FetchContent_GetProperties(ftxui)
FetchContent_GetProperties(nlohmann_json)

FetchContent_MakeAvailable(ftxui)
FetchContent_MakeAvailable(nlohmann_json)

add_executable(test_protocol_ui test_protocol_ui.cpp)
# target_include_directories(test_protocol_ui ${ftxui_INCLUDE})
target_link_libraries(test_protocol_ui
PRIVATE ftxui::screen
PRIVATE ftxui::dom
PRIVATE ftxui::component
PUBLIC nlohmann_json::nlohmann_json
)
29 changes: 29 additions & 0 deletions cli/test_protocol_ui.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <functional> // for function
#include <iostream> // for basic_ostream::operator<<, operator<<, endl, basic_ostream, basic_ostream<>::__ostream_type, cout, ostream
#include <string> // for string, basic_string, allocator
#include <vector> // for vector

#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Menu
#include "ftxui/component/component_options.hpp" // for MenuOption
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive

int main() {
using namespace ftxui;
auto screen = ScreenInteractive::TerminalOutput();

std::vector<std::string> entries = {
"entry 1",
"entry 2",
"entry 3",
};
int selected = 0;

MenuOption option;
option.on_enter = screen.ExitLoopClosure();
auto menu = Menu(&entries, &selected, option);

screen.Loop(menu);

std::cout << "Selected element = " << selected << std::endl;
}

0 comments on commit d810713

Please sign in to comment.