Using a library via Vcpkg
cmake
cmake_minimum_required(VERSION 3.28)
project(my-project)
find_package(ftxui REQUIRED)
add_executable(my-app main.cpp)
target_compile_features(my-app PRIVATE cxx_std_20)
target_link_libraries(my-app PRIVATE ftxui::dom ftxui::screen ftxui::component)
cpp
#include "ftxui/component/captured_mouse.hpp"
#include "ftxui/component/component.hpp"
#include "ftxui/component/component_options.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include <functional>
#include <iostream>
#include <string>
#include <vector>
int main() {
auto screen = ftxui::ScreenInteractive::TerminalOutput();
ftxui::MenuOption option;
option.on_enter = screen.ExitLoopClosure();
std::vector<std::string> entries = {
"entry 1",
"entry 2",
"entry 3",
};
int selected = 0;
auto menu = ftxui::Menu(&entries, &selected, option);
screen.Loop(menu);
std::cout << "Selected element = " << selected << std::endl;
}
json
{
"dependencies": ["ftxui"]
}
json
{
"version": 3,
"configurePresets": [
{
"name": "my-preset",
"binaryDir": "${sourceDir}/build",
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
]
}
sh
vcpkg install
cmake --preset my-preset
cmake --build build
./build/my-app
What is Vcpkg?
Vcpkg helps you manage C and C++ libraries on Windows, Linux and MacOS. This tool and ecosystem are constantly evolving, and we always appreciate contributions!
Here's a quick installation guide:
sh
cd ~
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
echo 'export VCPKG_ROOT="$HOME/vcpkg"' >> ~/.bashrc
echo 'export PATH="$PATH:$VCPKG_ROOT"' >> ~/.bashrc
powershell
cd "$Env:USERPROFILE"
git clone "https://github.com/microsoft/vcpkg.git"
cd vcpkg
./bootstrap-vcpkg.bat
# TODO: Add VCPKG_ROOT to env
# TODO: Add VCPKG_ROOT to PATH