### Meson Setup with Examples Enabled Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_meson.md Configure the Meson build to include example applications. ```bash meson setup builddir -Dexamples=true ninja -C builddir ``` -------------------------------- ### Meson Setup with Examples and Tests Enabled Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_meson.md Configure the Meson build to include both example applications and tests. ```bash meson setup builddir -Dexamples=true -Dtests=true ninja -C builddir meson test -C builddir ``` -------------------------------- ### Basic Meson Setup, Build, and Install Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_meson.md Configure the project with Meson, build the library using Ninja, and install it. ```bash meson setup builddir ninja -C builddir ninja -C builddir install ``` -------------------------------- ### Build and Install FTXUI from Source Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_manual.md Clone the FTXUI repository, configure the build with CMake, compile the project, and install it system-wide. Ensure you have CMake and a C++ compiler installed. ```bash git clone https://github.com/ArthurSonzogni/FTXUI.git cd FTXUI cmake -S . -B build -D FTXUI_ENABLE_INSTALL=ON cmake --build build -j sudo cmake --install build ``` -------------------------------- ### Install FTXUI using Vcpkg Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_vcpkg.md Install the FTXUI package using the vcpkg install command. Specify the target triplet for your build environment. ```bash vcpkg install --triplet x64-linux # or x64-windows / arm64-osx etc. ``` -------------------------------- ### Basic FTXUI Application Example Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_vcpkg.md A minimal C++ example demonstrating how to create a simple FTXUI application with a button. This requires including necessary FTXUI headers. ```cpp #include #include #include int main() { using namespace ftxui; auto screen = App::TerminalOutput(); auto button = Button("Click me", [] { std::cout << "Clicked!\n"; }); screen.Loop(button); } ``` -------------------------------- ### Generate DOM and Component Example Lists Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/CMakeLists.txt Calls the 'write_example_list' macro to generate markdown files for DOM and component examples, organizing them by type. ```cmake write_example_list("${CMAKE_CURRENT_BINARY_DIR}/dom_examples.md" "Example" module-dom-examples DOM_EXAMPLES) write_example_list("${CMAKE_CURRENT_BINARY_DIR}/component_examples.md" "Example" module-component-examples COMPONENT_EXAMPLES) ``` -------------------------------- ### Basic FTXUI Application Example Source: https://github.com/arthursonzogni/ftxui/blob/main/README.md This example demonstrates the basic structure of an FTXUI application, including creating a document with nested layouts (vbox, hbox), adding text elements with borders, and displaying progress gauges. It requires including the ftxui.hpp header. ```cpp #include using namespace ftxui; int main() { auto document = vbox({ hbox({ text("one") | border, text("two") | border | flex, text("three") | border | flex, }), gauge(0.25) | color(Color::Red), gauge(0.50) | color(Color::White), gauge(0.75) | color(Color::Blue), }); auto screen = Screen::Create(Dimension::Full()); Render(screen, document); screen.Print(); return 0; } ``` -------------------------------- ### Conditional Example Build Source: https://github.com/arthursonzogni/ftxui/blob/main/examples/CMakeLists.txt This snippet ensures examples are only built if FTXUI_BUILD_EXAMPLES is enabled. It prevents unnecessary compilation when examples are not desired. ```cmake if(NOT FTXUI_BUILD_EXAMPLES) return() endif() ``` -------------------------------- ### Run FTXUI Bazel Integration Examples Source: https://github.com/arthursonzogni/ftxui/blob/main/bazel/test/README.md Execute the compiled integration tests for both submodule and single-target dependency configurations. ```bash # Run the submodules version ./bazel-bin/smoke # Run the single-target version ./bazel-bin/smoke_single_dependency ``` -------------------------------- ### Meson Setup with Tests Enabled Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_meson.md Configure the Meson build to include and run tests. Google Test will be downloaded automatically if not found on the system. ```bash meson setup builddir -Dtests=true ninja -C builddir meson test -C builddir ``` -------------------------------- ### Example List Generation Macro Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/CMakeLists.txt Defines a macro to generate markdown files listing examples. It takes a file path, title, page name, and a list of examples, formatting them with links to demos and including their source code. ```cmake macro(write_example_list file title page examples) file(WRITE "${file}" "@page ${page} ${title}\n") file(APPEND "${file}" "@tableofcontents\n") foreach(example IN LISTS examples) get_filename_component(name "${example}" NAME_WE) file(APPEND "${file}" "# ${name}\n") # Add a markdown to the demo. URL example: # https://arthursonzogni.github.io/FTXUI/examples/?file=component/canvas_animated file(APPEND "${file}" "[Demo](https://arthursonzonson.github.io/FTXUI/examples/?file=${example})\n") file(APPEND "${file}" "@include examples/${example}.cpp\n") file(APPEND "${file}" "\n") endforeach() # Reference to the examples foreach(example IN LISTS examples) get_filename_component(name "${example}" NAME_WE) file(APPEND "${file}" "@example examples/${example}.cpp\n") endforeach() endmacro() ``` -------------------------------- ### Install FTXUI with AUR Helper Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_arch.md Use an AUR helper like `yay` to install the FTXUI package from the Arch User Repository. ```bash yay -S ftxui ``` -------------------------------- ### Enable FTXUI CMake Options Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_cmake.md Configure FTXUI build options such as examples, documentation, tests, and installation targets using CMake flags. ```cmake cmake -DFTXUI_BUILD_EXAMPLES=ON .. ``` -------------------------------- ### Create a Screen with Elements Source: https://github.com/arthursonzogni/ftxui/wiki/Screen Creates a screen and defines a layout of elements to be rendered. This example demonstrates a horizontal box with bordered text elements. ```c++ #include #include // ... ftxui::Dimention width; auto screen = ftxui::Scene::Create( width, height ); auto element = ftxui::hbox({ ftxui::text("Left") | ftxui::border, ftxui::text("Middle") | ftxui::border | ftxui::flex, ftxui::text("Right) | ftxui::border }); // ... ``` -------------------------------- ### Install Conan Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_conan.md Install Conan using pip. This is a prerequisite for managing FTXUI dependencies. ```powershell pip install conan ``` -------------------------------- ### Add openSUSE Repository and Install FTXUI Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_opensuse.md Use these commands to add the unofficial FTXUI repository and install the package on openSUSE. Note that this package is community-maintained. ```bash sudo zypper addrepo https://download.opensuse.org/repositories/devel:libraries:c_c++/openSUSE_Leap_$releasever/devel:libraries:c_c++.repo ``` ```bash sudo zypper install ftxui ``` -------------------------------- ### Create a Basic Terminal UI Layout Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/introduction.md This example demonstrates how to create a simple document with three text elements arranged horizontally using FTXUI. It shows basic element creation, styling with borders, layout with hbox, and rendering to the screen. ```cpp #include #include #include int main() { using namespace ftxui; // Create a simple document with three text elements. Element document = hbox({ text("left") | border, text("middle") | border | flex, text("right") | border, }); // Create a screen with full width and height fitting the document. auto screen = Screen::Create( Dimension::Full(), // Width Dimension::Fit(document) // Height ); // Render the document onto the screen. Render(screen, document); // Print the screen to the console. screen.Print(); } ``` -------------------------------- ### FTXUI Example Function Source: https://github.com/arthursonzogni/ftxui/blob/main/examples/CMakeLists.txt Defines a CMake function to streamline the creation of executable examples. It links the example to the necessary libraries and sets C++20 as a compile feature. ```cmake function(example name) add_executable(ftxui_example_${name} ${name}.cpp) target_link_libraries(ftxui_example_${name} PUBLIC ${DIRECTORY_LIB}) file(RELATIVE_PATH dir ${EXAMPLES_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) set_property(GLOBAL APPEND PROPERTY FTXUI::EXAMPLES ${dir}/${name}) target_compile_features(ftxui_example_${name} PRIVATE cxx_std_20) endfunction(example) ``` -------------------------------- ### Install FTXUI Dependencies with Conan Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_conan.md Install FTXUI and its dependencies using Conan. This command configures the build output directory and builds any missing dependencies. ```powershell conan install . --output-folder=build --build=missing ``` -------------------------------- ### Install FTXUI with CMake FetchContent Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/getting-started.md Integrate FTXUI into your CMake project by declaring and making it available. Link your executable against the ftxui library. ```cmake include(FetchContent) FetchContent_Declare(ftxui GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui GIT_TAG main # or a specific version like v7.0.0 ) FetchContent_MakeAvailable(ftxui) add_executable(my_app main.cpp) target_link_libraries(my_app PRIVATE ftxui::ftxui) ``` -------------------------------- ### Install FTXUI Debian/Ubuntu Package Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_debian.md Use this command to install the FTXUI development package on Debian-based systems. ```bash sudo apt install libftxui-dev ``` -------------------------------- ### Start Interactive Screen Loop Source: https://github.com/arthursonzogni/ftxui/wiki/Screen Sets up the main loop for an interactive screen, rendering a component. The `Loop()` function blocks the current thread. ```c++ auto screen = ftxui::ScreenInteractive::Fullscreen(); auto finalRenderer = ftxui::Renderer([&](){ // ... }); screen.Loop(finalComponent); ``` -------------------------------- ### Example of POSIX Pipe Usage Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/posix_pipe.md Demonstrates connecting the output of the 'ls -l' command to an FTXUI application 'interactive_grep' using a pipe. ```bash ls -l | interactive_grep ``` -------------------------------- ### Use FTXUI as a Meson subproject dependency Source: https://github.com/arthursonzogni/ftxui/blob/main/README.md Example of how to declare FTXUI as a dependency in a Meson project's build file. ```meson ftxui_dep = dependency('ftxui-component') ``` -------------------------------- ### CMakeLists.txt for FTXUI Project Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_conan.md Configure your CMake build system to find and link against the FTXUI library installed by Conan. Sets the C++ standard and defines the executable. ```cmake cmake_minimum_required(VERSION 3.20) project(ftxui-demo) # Set the C++ standard set(CMAKE_CXX_STANDARD 20) # Find the FTXUI package installed via Conan find_package(ftxui CONFIG REQUIRED) # Create the executable add_executable(demo demo.cpp) # Link the executable to the FTXUI library target_link_libraries(demo PRIVATE ftxui::component) ``` -------------------------------- ### Integrate FTXUI using find_package with CMake Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_cmake.md Use find_package when FTXUI is installed system-wide or via a package manager. Ensure the package is discoverable via CMAKE_PREFIX_PATH. ```cmake find_package(ftxui REQUIRED) add_executable(main main.cpp) target_link_libraries(main PRIVATE ftxui::screen PRIVATE ftxui::dom PRIVATE ftxui::component ) ``` -------------------------------- ### Makefile without pkg-config for FTXUI Source: https://github.com/arthursonzogni/ftxui/wiki/Makefile This Makefile manually specifies the include and library paths for FTXUI. Use this if pkg-config is not installed or configured on your system. ```makefile CC = g++ CFLAGS = -g -Wall FTXUI_CFLAGS = -I/usr/local/include FTXUI_LDFLAGS = -L/usr/local/lib -lftxui-component -lftxui-dom -lftxui-screen all: run run: main ./main main: main.o $(CC) main.o $(FTXUI_LDFLAGS) -o main main.o: main.cpp $(CC) -c main.cpp $(CFLAGS) $(FTXUI_CFLAGS) -o main.o clean: rm main.o rm main ``` -------------------------------- ### Doxygen Dependency Check Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/CMakeLists.txt Ensures Doxygen is installed and available. If not found, it prints a message and returns. ```cmake find_package(Doxygen) if (NOT DOXYGEN_FOUND) message("Doxygen need to be installed to generate the doxygen documentation") return() endif() ``` -------------------------------- ### Add Interactivity with FTXUI Components Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/getting-started.md Build an interactive terminal application using FTXUI's Component module and the App class. This example creates a simple menu component. ```cpp #include #include #include int main() { using namespace ftxui; std::vector entries = { "Entry 1", "Entry 2", "Entry 3", }; int selected = 0; // Create a menu component auto menu = Menu(&entries, &selected); // You can decorate components using the pipe operator. auto component = menu | border; // Start the main loop auto app = App::TerminalOutput(); app.Loop(component); return 0; } ``` -------------------------------- ### Drawing on a Canvas Source: https://github.com/arthursonzogni/ftxui/blob/main/README.md Utilize the Canvas element for custom drawing operations within the terminal. This example demonstrates basic drawing capabilities. ```cpp #include // ... inside a component or renderer canvas(10, 10, [](Canvas &c) { c.draw_pixel(5, 5, Color::Red); }); ``` -------------------------------- ### Colored Table Borders and Separators Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Apply specific colors to table borders and separators using decorators. Examples show red borders and blue vertical separators. ```cpp // Apply a red border to the whole table. table.SelectAll().Border(LIGHT, color(Color::Red)); // Apply a blue separator to the first row. table.SelectRow(0).SeparatorVertical(LIGHT, color(Color::Blue)); ``` -------------------------------- ### Build FTXUI with Meson Source: https://github.com/arthursonzogni/ftxui/blob/main/README.md Basic commands to set up a build directory and compile FTXUI using Meson. ```bash meson setup builddir ninja -C builddir ``` -------------------------------- ### Create a Basic Screen Source: https://github.com/arthursonzogni/ftxui/wiki/Screen Initializes a screen object with specified dimensions. This screen is ready to have elements rendered onto it. ```c++ #include #include // ... ftxui::Dimention width; auto screen = ftxui::Scene::Create( width, height ); // ... ``` -------------------------------- ### Basic Table Creation and Styling Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Create a table from data and apply basic styling like borders and text decoration to rows and cells. ```cpp auto table = Table({ {"Planet", "Radius", "Mass"}, {"Mercury", "2440", "0.330"}, {"Venus", "6052", "4.87"}, {"Earth", "6371", "5.97"}, {"Mars", "3390", "0.642"}, }); table.SelectAll().Border(LIGHT); table.SelectRow(0).Decorate(bold); table.SelectRow(0).SeparatorVertical(LIGHT); table.SelectRow(0).Border(DOUBLE); auto document = table.Render(); ``` -------------------------------- ### Build FTXUI Library with Nix Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_nix.md Use this command to build the FTXUI library directly from its GitHub repository using Nix. The output is available via the 'result' symlink. ```bash nix build github:ArthurSonzogni/FTXUI ``` -------------------------------- ### Create Project Directory Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_conan.md Create a new directory for your FTXUI project and navigate into it. ```powershell mkdir C:\ftxui-demo cd C:\ftxui-demo ``` -------------------------------- ### FTXUI Demo Application Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_conan.md A simple C++ program demonstrating basic FTXUI elements like text, bold formatting, and color. It renders a styled string to the console. ```cpp #include #include #include int main() { using namespace ftxui; auto document = hbox({ text(" Hello "), text("FTXUI ") | bold | color(Color::Red), text(" world! ") }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); std::cout << screen.ToString() << std::endl; return 0; } ``` -------------------------------- ### Modify Cell Properties Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-screen.md Provides a concise example of accessing a cell and modifying its character, bold style, and foreground/background colors. ```cpp auto& cell = screen.CellAt(x, y); cell.character = "X"; cell.bold = true; cell.foreground_color = Color::Red; ``` -------------------------------- ### Define a simple layout with ftxui::Element Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Demonstrates creating a basic layout using vbox, text, gauge, and border decorators. Elements can be combined and styled using operators like '|' and '|='. ```cpp namespace ftxui { ... // Define the document Element document = vbox({ text("The window") | bold | color(Color::Blue), gauge(0.5) text("The footer") }); // Add a border, by calling the `ftxui::border` decorator function. document = border(document); // Add another border, using the pipe operator. document = document | border. // Add another border, using the |= operator. document |= border ... } ``` -------------------------------- ### Build All Bazel Targets Source: https://github.com/arthursonzogni/ftxui/blob/main/bazel/test/README.md Use this command to build all targets defined in the Bazel workspace. ```bash bazel build //... ``` -------------------------------- ### Build FTXUI with Make (Quiet) Source: https://github.com/arthursonzogni/ftxui/blob/main/GEMINI.md Builds the FTXUI project using Make with quiet output, applicable if a Makefile exists in the build directory. ```bash make -C build -s ``` -------------------------------- ### Build FTXUI with Ninja (Alternative) Source: https://github.com/arthursonzogni/ftxui/blob/main/GEMINI.md Builds the FTXUI project using Ninja, typically used as an alternative to Make when a Makefile is not present. ```bash ninja -C build ``` -------------------------------- ### Configure and Build Project with Vcpkg Toolchain Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_vcpkg.md Configure and build your project using CMake, specifying the Vcpkg toolchain file. This ensures Vcpkg dependencies are correctly found and linked. ```bash cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build build ./build/main ``` -------------------------------- ### Import and Use FTXUI C++20 Modules Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/cpp20-modules.md Import the entire FTXUI library using `import ftxui;` or specific modules like `ftxui.screen` and `ftxui.dom` for targeted functionality. Requires a C++20 compatible compiler and CMake 3.20+. ```cpp import ftxui; using ftxui::App; using ftxui::Button; using ftxui::Component; int main() { App app = App::TerminalOutput(); Component button = Button("Click me", app.ExitLoopClosure()); screen.Loop(button); return 0; } ``` ```cpp import ftxui.screen; import ftxui.dom; // Use only screen and dom functionalities... ``` -------------------------------- ### Filter Input Characters with ftxui::CatchEvent Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-component.md Use ftxui::CatchEvent to filter characters entered into an input component. This example shows how to restrict input to digits and limit the length. ```cpp std::string phone_number; Component input = Input(&phone_number, "phone number"); // Filter out non-digit characters. input |= CatchEvent([&](Event event) { return event.is_character() && !std::isdigit(event.character()[0]); }); // Filter out characters past the 10th one. input |= CatchEvent([&](Event event) { return event.is_character() && phone_number.size() >= 10; }); ``` -------------------------------- ### XMake Configuration for FTXUI Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_xmake.md Use this snippet in your xmake.lua file to add FTXUI as a dependency and link it to your target. Ensure the FTXUI package is available in your xmake repositories. ```lua add_requires("ftxui", {system = false}) target("demo") set_kind("binary") add_files("src/*.cpp") add_packages("ftxui") ``` -------------------------------- ### Create a Static UI with FTXUI DOM Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/getting-started.md Define a static UI layout using FTXUI's DOM elements like vbox, hbox, text, separator, and decorators. Render the document to the screen. ```cpp #include #include int main() { using namespace ftxui; // Define the document structure Element document = vbox({ text("FTXUI Getting Started") | bold | center, separator(), hbox({ text("Left Panel") | border, vbox({ text("Main Content Area") | flex, separator(), text("Footer Information") | dim, }) | border | flex, }) | flex, }); // Create the screen and render auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document); screen.Print(); return 0; } ``` -------------------------------- ### Fetch Doxygen Awesome CSS Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/CMakeLists.txt Fetches the 'doxygen-awesome-css' theme using FetchContent for enhanced documentation styling. It declares, makes available, and retrieves properties of the fetched content. ```cmake include(FetchContent) FetchContent_Declare( doxygen-awesome-css GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css.git GIT_TAG v2.3.4 ) FetchContent_MakeAvailable(doxygen-awesome-css) FetchContent_GetProperties(doxygen-awesome-css SOURCE_DIR AWESOME_CSS_DIR) ``` -------------------------------- ### Create a Fullscreen Interactive Screen Source: https://github.com/arthursonzogni/ftxui/wiki/Screen Initializes an interactive screen that takes up the entire fullscreen. This screen will manage components for user interaction. ```c++ #include // ... auto screen = ftxui::ScreenInteractive::Fullscreen(); // ... ``` -------------------------------- ### Makefile with pkg-config for FTXUI Source: https://github.com/arthursonzogni/ftxui/wiki/Makefile Use this Makefile when pkg-config is available to automatically fetch the necessary compiler and linker flags for FTXUI. This simplifies dependency management. ```makefile CC = g++ CFLAGS = -g -Wall FTXUI_CFLAGS = `pkg-config --cflags ftxui` FTXUI_LDFLAGS = `pkg-config --libs ftxui` all: run run: main ./main main: main.o $(CC) main.o $(FTXUI_LDFLAGS) -o main main.o: main.cpp $(CC) -c main.cpp $(CFLAGS) $(FTXUI_CFLAGS) -o main.o clean: rm main.o rm main ``` -------------------------------- ### Link FTXUI Libraries in BUILD.bazel Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_bazel.md Specify the FTXUI components required for your C++ binary in the BUILD.bazel file. ```starlark cc_binary( name = "main", srcs = ["main.cpp"], deps = [ "@ftxui//:component", "@ftxui//:dom", "@ftxui//:screen", ], ) ``` -------------------------------- ### Generate Amalgamated Files Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_amalgamated.md Run this command from the root of the cloned FTXUI repository to generate the amalgamated header and source files. ```bash ./tools/amalgamate.py ``` -------------------------------- ### Define Screen Dimensions Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-screen.md Illustrates how to create a screen with specific dimensions using ftxui::Dimension. Supports full terminal size, fitting an element, or a fixed number of rows/columns. ```cpp auto screen = ftxui::Screen::Create( ftxui::Dimension::Full(), // width ftxui::Dimension::Fixed(10) // height ); ``` ```cpp auto screen = ftxui::Screen::Create( ftxui::Dimension::Fixed(5), ftxui::Dimension::Fixed(5) ); ``` -------------------------------- ### Reconfiguring Meson Build Options Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_meson.md Modify build options for an existing Meson build directory, such as enabling tests, and then rebuild. ```bash meson configure builddir -Dtests=true ninja -C builddir ``` -------------------------------- ### Create and Modify Screen Cells Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-screen.md Demonstrates how to create a screen with specified dimensions, access individual cells using CellAt, and modify their properties such as character, foreground color, background color, and bold style. Out-of-bounds coordinates return a dummy cell. ```cpp #include #include void main() { auto screen = ftxui::Screen::Create( ftxui::Dimension::Full(), // Use full terminal width ftxui::Dimension::Fixed(10) // Fixed height of 10 rows ); // Access a specific cell at (10, 5) auto& cell = screen.CellAt(10, 5); // Set properties of the cell. cell.character = "X"; cell.foreground_color = ftxui::Color::Red; cell.background_color = ftxui::Color::RGB(0, 255, 0); cell.bold = true; // Set bold style screen.Print(); // Print the screen to the terminal } ``` ```cpp auto screen = ftxui::Screen::Create( ftxui::Dimension::Fixed(5), ftxui::Dimension::Fixed(5) ); auto& cell = screen.CellAt(3, 3); cell.character = "X"; cell.bold = true; cell.foreground_color = ftxui::Color::Red; cell.background_color = ftxui::Color::RGB(0, 255, 0); screen.Print(); ``` -------------------------------- ### Link FTXUI libraries in order Source: https://github.com/arthursonzogni/ftxui/blob/main/README.md When linking FTXUI manually, ensure 'ftxui-component' is listed before other FTXUI libraries. ```bash g++ . . . -lftxui-component -lftxui-dom -lftxui-screen . . . ``` -------------------------------- ### Add FTXUI as a Nix Flake Input Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_nix.md Include this snippet in your `flake.nix` file to add FTXUI as a dependency. You can then reference packages like `ftxui.packages..ftxui` in your outputs. ```nix { inputs.ftxui.url = "github:ArthurSonzogni/FTXUI"; } ``` -------------------------------- ### Create and Draw on Canvas Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Initializes a Canvas with specified dimensions and draws a line on it. The canvas is then converted into a renderable FTXUI element. ```cpp auto c = Canvas(100, 100); c.DrawPointLine(10, 10, 80, 10, Color::Red); auto element = canvas(c); ``` -------------------------------- ### Clean Meson Build Directory Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_meson.md Remove the build directory and re-initialize the Meson build system. ```bash rm -rf builddir meson setup builddir ``` -------------------------------- ### Configure CMakeLists.txt for FTXUI Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_vcpkg.md Integrate FTXUI into your CMake build system. Find the FTXUI package and link its components to your executable. ```cmake cmake_minimum_required(VERSION 3.15) project(my_project) # Make sure vcpkg toolchain file is passed at configure time find_package(ftxui CONFIG REQUIRED) add_executable(main main.cpp) target_link_libraries(main PRIVATE ftxui::screen PRIVATE ftxui::dom PRIVATE ftxui::component ) ``` -------------------------------- ### Integrate FTXUI with CMake FetchContent Source: https://github.com/arthursonzogni/ftxui/blob/main/README.md Use CMake FetchContent to declare and make FTXUI available as a dependency. Link against the umbrella target or specific submodules. ```cmake include(FetchContent) FetchContent_Declare(ftxui GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui GIT_TAG v7.0.0 ) FetchContent_MakeAvailable(ftxui) target_link_libraries(your_target PRIVATE # Use the umbrella target (recommended) ftxui::ftxui # Or chose a submodule # ftxui::component # ftxui::dom # ftxui::screen ) ``` -------------------------------- ### Build FTXUI Project with CMake Source: https://github.com/arthursonzogni/ftxui/blob/main/GEMINI.md Builds the FTXUI project using CMake. This command does not support quiet output. ```bash cmake --build build ``` -------------------------------- ### Render Element to Screen Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-screen.md Shows the process of rendering an ftxui::Element to a created screen and then printing the screen to the terminal. ```cpp ftxui::Render(screen, element); screen.Print(); ``` -------------------------------- ### Create a window with a header using ftxui::window Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Adds a border with a specified header string around an element. ```cpp window("The window", text("The element")) ``` -------------------------------- ### Configure Doxyfile Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/CMakeLists.txt Configures the Doxyfile using a template, ensuring all necessary settings are in place for Doxygen to generate the documentation. ```cmake configure_file(Doxyfile.in Doxyfile @ONLY) ``` -------------------------------- ### Include ftxui::dom::elements.hpp Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Include the necessary header file to access the list of all ftxui elements. ```cpp #include ``` -------------------------------- ### Table Selection Methods Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Demonstrates various methods for selecting parts of a table for styling, including selecting all, specific cells, rows, columns, or rectangular regions. ```cpp ftxui::TableSelection::SelectAll(); ftxui::TableSelection::SelectCell(column, row); ftxui::TableSelection::SelectRow(row_index); ftxui::TableSelection::SelectRows(row_min, row_max); ftxui::TableSelection::SelectColumn(column_index); ftxui::TableSelection::SelectColumns(column_min, column_max); ftxui::TableSelection::SelectRectangle(column_min, column_max, row_min, row_max); ``` -------------------------------- ### Create Simplified Linear Gradients Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Provides simplified constructors for `ftxui::LinearGradient` when only two colors are needed, optionally specifying the angle. ```cpp LinearGradient(Color::Red, Color::Blue); LinearGradient(45, Color::Red, Color::Blue); ``` -------------------------------- ### Build Individual Bazel Targets Source: https://github.com/arthursonzogni/ftxui/blob/main/bazel/test/README.md Build specific targets for testing individual submodules or the single ftxui target. ```bash # Test using individual submodules bazel build //:smoke # Test using the single ftxui target bazel build //:smoke_single_dependency ``` -------------------------------- ### Add FTXUI Dependency to vcpkg.json Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_vcpkg.md Specify FTXUI as a project dependency in your vcpkg.json file. Ensure the version constraint is met. ```json { "name": "your-project", "version-string": "0.1.0", "dependencies": [ { "name": "ftxui", "version>=": "7.0.0" } ] } ``` -------------------------------- ### Use 16-Color Palette for Text Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Demonstrates applying specific colors from the 16-color palette to text elements using the `color()` and `bgcolor()` decorators and the pipe operator. ```cpp text("Blue foreground") | color(Color::Blue); text("Blue background") | bgcolor(Color::Blue); text("Black on white") | color(Color::Black) | bgcolor(Color::White); ``` -------------------------------- ### Build FTXUI with C++20 Modules Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/cpp20-modules.md Use the `FTXUI_BUILD_MODULES=ON` CMake option with a compatible generator like Ninja to build FTXUI as C++20 modules. Ensure your compiler and CMake version are C++20 compatible. ```sh cmake \ -DCMAKE_GENERATOR=Ninja \ -DFTXUI_BUILD_MODULES=ON \ .. ninja ``` -------------------------------- ### Configure CMake Build for FTXUI Source: https://github.com/arthursonzogni/ftxui/blob/main/GEMINI.md Configures the CMake build system for FTXUI, enabling tests. Ensure the build directory is clean before configuring. ```bash cmake -B build -DFTXUI_BUILD_TESTS=ON ``` -------------------------------- ### Compile with Amalgamated Version Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_amalgamated.md When compiling your project with the amalgamated FTXUI files, ensure you are using C++17 and linking against threads. ```bash g++ -std=c++17 your_main.cpp [ftxui.cpp] -o your_app -lpthread ``` -------------------------------- ### Force Screen Redraw using Threading Source: https://github.com/arthursonzogni/ftxui/wiki/Screen Demonstrates how to force a screen redraw by posting a custom event within a separate thread. This is necessary because `Screen::Loop()` is blocking. ```c++ // ... auto screen = ftxui::ScreenInteractive::Fullscreen(); auto screenRedraw = std::thread([&](){ while(running){ screen.PostEvent(ftxui::Event::Custom); std::this_thread::sleep_for(std::chrono::milliseconds(50)); // Prevent High CPU Usage. } }); //... screen.Loop(finalRenderer); running = false; screenRedraw.join(); //... ``` -------------------------------- ### Add FTXUI Dependency in MODULE.bazel Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_bazel.md Declare the FTXUI library and its version in your MODULE.bazel file when using Bzlmod. ```starlark bazel_dep(name = "ftxui", version = "7.0.0") ``` -------------------------------- ### FTXUI Meson Subproject Wrap File Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_meson.md Configuration for using FTXUI as a subproject in your own Meson build. This wrap file specifies the Git repository and revision. ```ini [wrap-git] url = https://github.com/ArthurSonzogni/FTXUI.git revision = v7.0.0 [provide] ftxui-screen = ftxui_screen_dep ftxui-dom = ftxui_dom_dep ftxui-component = ftxui_component_dep ``` -------------------------------- ### Link FTXUI modules or umbrella target in Bazel BUILD.bazel Source: https://github.com/arthursonzogni/ftxui/blob/main/README.md Specify dependencies in the BUILD.bazel file, choosing between individual FTXUI submodules or the combined ftxui target. ```starlark cc_binary( name = "your_target", srcs = ["your_source.cc"], deps = [ # Choose submodules "@ftxui//:component", "@ftxui//:dom", "@ftxui//:screen", # Or use the single ftxui target (includes all modules) # "@ftxui//:ftxui", ], ) ``` -------------------------------- ### Apply Foreground and Background Colors Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Use the `color()` and `bgcolor()` decorators to set the foreground and background colors of text elements, respectively. Supports various color palettes. ```cpp Decorator color(Color); Decorator bgcolor(Color); ``` -------------------------------- ### Combine Elements with vbox, hbox, and separator Source: https://github.com/arthursonzogni/ftxui/blob/main/README.md Use vbox and hbox to arrange elements vertically and horizontally. The separator element can be used to divide UI sections. Elements can be enclosed in a border using the border decorator. ```cpp Element document = vbox({ text("top"), separator(), text("bottom"), }) | border; ``` -------------------------------- ### Run All FTXUI Tests Quietly Source: https://github.com/arthursonzogni/ftxui/blob/main/GEMINI.md Executes all tests within the build directory, showing output only on failure and using quiet mode. ```bash ctest --test-dir build --output-on-failure --quiet ``` -------------------------------- ### Conan Configuration File Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_conan.md Define project dependencies and build system integration for Conan. This file declares FTXUI as a requirement and specifies CMake generators. ```ini [requires] ftxui/6.0.2 [generators] CMakeDeps CMakeToolchain [layout] cmake_layout ``` -------------------------------- ### Chain Text Styles Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Demonstrates applying multiple text styles (bold and underlined) to a text element by chaining decorators using the pipe operator. ```cpp text("This text is bold and underlined") text("This text is bold") | bold | underlined ``` -------------------------------- ### Convert Screen to String Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-screen.md Converts the screen content to a std::string representation, which can then be printed or manipulated further. ```cpp auto screen = ...; std::cout << screen.ToString(); ``` -------------------------------- ### Create a Graph Element Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Use the `graph()` function to create a graph element. Requires a `GraphFunction` to be defined. ```cpp Element graph(GraphFunction); ``` -------------------------------- ### Horizontal Box Layout with Flex Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Arrange elements horizontally. Use `flex` to make elements expandable to fill available space. ```cpp hbox({ text("left") | border , text("middle") | border | flex, text("right") | border, }); ``` ```cpp hbox({ text("left") | border , text("middle") | border | flex, text("right") | border | flex, }); ``` -------------------------------- ### Define a Custom Linear Gradient Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Constructs a `ftxui::LinearGradient` with a specified angle and multiple color stops. The `AddStop()` method defines the color at a specific position (0.0 to 1.0). ```cpp auto gradient = LinearGradient() .Angle(45) .AddStop(0.0, Color::Red) .AddStop(0.5, Color::Green) .AddStop(1.0, Color::Blue); ``` -------------------------------- ### Create a paragraph with word wrapping using ftxui::paragraph Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Displays text with automatic word wrapping based on the container's width. Various alignment options are available. ```cpp paragraph("A very long text") ``` ```cpp namespace ftxui { Element paragraph(std::string text); Element paragraphAlignLeft(std::string text); Element paragraphAlignRight(std::string text); Element paragraphAlignCenter(std::string text); Element paragraphAlignJustify(std::string text); } ``` -------------------------------- ### FTXUI Meson Subproject Integration Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_meson.md How to declare the dependency on FTXUI in your Meson project's meson.build file and link it to your executable. ```meson ftxui_component_dep = dependency('ftxui-component', fallback: ['ftxui', 'ftxui_component_dep']) executable('my_app', 'main.cpp', dependencies: ftxui_component_dep, ) ``` -------------------------------- ### Display simple text with ftxui::text Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md The most basic element for displaying a string of text. ```cpp text("I am a piece of text"); ``` -------------------------------- ### Table Styling with Decorators and Borders Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Apply decorators and borders to selected parts of a table. `Decorate` applies to cells and borders, while `DecorateCells` applies only to cells. ```cpp ftxui::TableSelection::Decorate(Decorator); ftxui::TableSelection::DecorateCells(Decorator); ftxui::TableSelection::Border(BorderStyle); ftxui::TableSelection::Separator(BorderStyle); ``` -------------------------------- ### Include Header-Only Amalgamated Version Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_amalgamated.md Define FTXUI_IMPLEMENTATION in exactly one C++ file before including the header to use the header-only amalgamated version. Other files can include it without the define. ```cpp #define FTXUI_IMPLEMENTATION #include "ftxui_all.hpp" ``` ```cpp #include "ftxui_all.hpp" ``` -------------------------------- ### FTXUI Default Piped Input Handling Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/posix_pipe.md Shows the default behavior where FTXUI automatically handles piped input and keyboard interaction. This is enabled by default. ```cpp auto screen = App::Fullscreen(); // screen.HandlePipedInput(true); // This is enabled by default screen.Loop(component); ``` -------------------------------- ### Redirect stdin/stdout to Console (C++) Source: https://github.com/arthursonzogni/ftxui/wiki/Redirect-stdin---stdout Use this code on Linux to redirect stdin and stdout back to the console when they have been redirected elsewhere. It backs up the original file descriptors before rerouting. ```cpp #include // dup #include // fileno #include // freopen [...] // Backup the current file descriptor for stdin/stdout auto old_stdout = dup(fileno(stdout)); auto old_stdin = dup(fileno(stdin)); // Reroute stdin and stdout toward the console. stdin = freopen("/dev/tty", "r", stdin); stdout = freopen("/dev/tty", "w", stdout); ``` -------------------------------- ### Fine-grained Border Decoration Methods Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Provides methods to apply decorators to specific borders (left, right, top, bottom) and separators (vertical, horizontal) of a table selection. ```cpp ftxui::TableSelection::DecorateBorder(Decorator); ftxui::TableSelection::DecorateBorderLeft(Decorator); ftxui::TableSelection::DecorateBorderRight(Decorator); ftxui::TableSelection::DecorateBorderTop(Decorator); ftxui::TableSelection::DecorateBorderBottom(Decorator); ftxui::TableSelection::DecorateSeparator(Decorator); ftxui::TableSelection::DecorateSeparatorVertical(Decorator); ftxui::TableSelection::DecorateSeparatorHorizontal(Decorator); ``` -------------------------------- ### Conditional Documentation Build Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/CMakeLists.txt This snippet controls whether the documentation build process is executed. It returns early if FTXUI_BUILD_DOCS is not set. ```cmake if(NOT FTXUI_BUILD_DOCS) return() endif() ``` -------------------------------- ### Custom Target for Doxygen Documentation Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/CMakeLists.txt Defines a custom target 'doc' that executes Doxygen with the configured Doxyfile. This allows building the documentation as part of the CMake build process. ```cmake add_custom_target(doc COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating API documentation with Doxygen" VERBATIM ) ``` -------------------------------- ### Create Linear Gradient Decorators Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Use `color()` and `bgcolor()` decorators with `LinearGradient` to apply gradient effects to text foreground or background. A `LinearGradient` is defined by an angle and color stops. ```cpp Decorator color(const LinearGradient&); Decorator bgcolor(const LinearGradient&); ``` -------------------------------- ### Link FTXUI Modules with CMake Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/cpp20-modules.md Use `target_link_libraries` in your CMake build system to correctly link against the FTXUI C++20 modules for your executable. This ensures the compiler and linker have the necessary flags. ```cmake target_link_libraries(my_executable #...whatever... PRIVATE ftxui::modules ) ``` -------------------------------- ### Print Screen to Terminal Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-screen.md Renders the screen content to the standard output. This method is typically called after modifying screen cells. ```cpp auto screen = ...; screen.Print(); ``` -------------------------------- ### Exit Interactive Screen Loop Programmatically Source: https://github.com/arthursonzogni/ftxui/wiki/Screen Shows how to programmatically exit the interactive screen's main loop by calling `Exit()` from within the loop. ```c++ When inside: ftxui::ScreenInteractive::Loop(), the loop can be ended by calling: ftxui::ScreenInteractive::Exit() ``` -------------------------------- ### Create Paragraphs with Alignment Source: https://github.com/arthursonzogni/ftxui/blob/main/README.md Use the paragraph functions to create text elements that support wrapping. Various alignment options are available, including left, right, center, and justify. ```cpp Element paragraph(string text); Element paragraphAlignLeft(string text); Element paragraphAlignRight(string text); Element paragraphAlignCenter(string text); Element paragraphAlignJustify(string text); ``` -------------------------------- ### Link FTXUI in CMakeLists.txt Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/installation_arch.md Add FTXUI as a dependency in your CMake project to link against its screen, DOM, and component modules. ```cmake find_package(ftxui REQUIRED) add_executable(main main.cpp) target_link_libraries(main PRIVATE ftxui::screen PRIVATE ftxui::dom PRIVATE ftxui::component ) ``` -------------------------------- ### Define TrueColor RGB and HSV Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Constructs `ftxui::Color` objects using RGB or HSV values for terminals supporting TrueColor. Use `RGB(red, green, blue)` or `HSV(hue, saturation, value)` constructors. ```cpp ftxui::Color::RGB(uint8_t red, uint8_t green, uint8_t blue); ftxui::Color::HSV(uint8_t hue, uint8_t saturation, uint8_t value); ``` -------------------------------- ### Disabling FTXUI Piped Input Handling Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/posix_pipe.md Illustrates how to explicitly disable the piped input handling feature by calling HandlePipedInput(false) before the main application loop. ```cpp auto screen = App::Fullscreen(); screen.HandlePipedInput(false); // Turn off piped input handling screen.Loop(component); ``` -------------------------------- ### Emscripten WebAssembly Configuration Source: https://github.com/arthursonzogni/ftxui/blob/main/examples/CMakeLists.txt Configures files for Emscripten when building for WebAssembly. It iterates through a list of common web assets and configures them for the target environment. ```cmake if (EMSCRIPTEN) get_property(EXAMPLES GLOBAL PROPERTY FTXUI::EXAMPLES) foreach(file "index.css" "index.html" "index.mjs" "run_webassembly.py" "sw.js" ) configure_file(${file} ${file}) endforeach(file) endif() ``` -------------------------------- ### Apply 256-Color Palette to Text Source: https://github.com/arthursonzogni/ftxui/blob/main/doc/module-dom.md Applies a color from the 256-color palette to a text element using the `color()` decorator. ```cpp text("HotPink") | color(Color::HotPink); ```