FTXUI Documentation
repository·main·Indexed 27 days ago
https://github.com/arthursonzogni/ftxuiA functional-style C++ library for building cross-platform terminal user interfaces inspired by reactive frameworks like React. FTXUI supports keyboard and mouse navigation, UTF8, animations, and C++20 modules without external dependencies. It is organized into three modules: screen (low-level rendering), dom (layout and composition), and component (user interaction). Compatible with Linux, MacOS, WebAssembly, and Windows.
What's inside FTXUI
- FTXUI is a simple, cross-platform C++ library for creating terminal-based user interfaces. It features a functional style inspired by React, requires no external dependencies, and supports keyboard and mouse navigation. It also provides support for UTF8, fullwidth characters, animations, and custom drawing.
Overview of FTXUI
mainFTXUI (Functional Terminal (X) User interface) is a cross-platform C++ library designed for creating terminal-based user interfaces. It uses a functional style inspired by React, allowing for simple and elegant syntax.
Key features include:
- Keyboard and mouse navigation.
- Support for UTF8 and fullwidth characters.
- Support for animations and drawing (canvas).
- No external dependencies.
- C++20 Module support.
- Cross-platform compatibility: Linux, MacOS, WebAssembly, and Windows.
Use ftxui/screen for low-level rendering
mainThe
ftxui/screenmodule is the foundation of the library, providing low-level terminal drawing capabilities. Use it when you need direct control over a 2D grid of styled characters.Key entities:
ftxui::Screen: A 2D grid of styled characters.ftxui::Cell: The fundamental unit of rendering.- Helpers:
ftxui::ColorandDimensionfor styling and sizing.
Use the ftxui::component module for interactive UIs
mainThe
ftxui::componentmodule provides logic for interactive components that respond to user events like keyboard and mouse input. Whileftxui::Elementis used for rendering single static frames,ftxui::Componentis used for dynamic user interfaces that maintain state and update across multiple frames.Key concepts:
ftxui::App: Defines the main loop that renders a component.ftxui::Component: A shared pointer to aftxui::ComponentBase.ftxui::ComponentBase: DefinesRender()(how to draw),OnEvent()(how to react), andAdd()(to build parent/child relationships for keyboard navigation).
Include the header to access predefined components:
#include "ftxui/component/component.hpp"Use ftxui/component for interactive widgets
mainThe
ftxui/componentmodule is the highest level of the library, providing stateful and interactive widgets. Use this module to build applications that respond to keyboard or cursor input.Key entities:
ftxui::Component: Stateful, interactive widgets that support composition.- Built-in widgets:
CheckboxInputMenuButton
Understand the FTXUI module hierarchy
mainFTXUI is organized into three hierarchical modules:
- Screen: The lowest level. Handles terminal state, colors, and the raw character grid.
- DOM: The layout engine. Provides
Elements that can be composed for responsive layouts. - Component: The interactive layer. Handles user input (keyboard, mouse) and manages the application's main loop.
Use ftxui/dom for layout and composition
mainThe
ftxui/dommodule provides a tree-based structure for building structured and responsive user interfaces. It sits above the screen module and allows you to compose complex layouts.Key entities:
ftxui::Element: A tree structure used for layout and UI composition.Render(): Method used to draw anElementonto aftxui::Screen.
Install FTXUI on Debian and Ubuntu
mainYou can install unofficial pre-built FTXUI packages using
apt. The following packages are available:libftxui-dev: Development filesftxui-doc: Documentationftxui-examples: Example projectslibftxui-component<version>libftxui-dom<version>libftxui-screen<version>
Note: These packages are unofficial and are maintained by the community, not the FTXUI team.
sudo apt install libftxui-devInstall FTXUI using Vcpkg CLI
mainInstall the FTXUI package using the vcpkg command line tool. You should specify the appropriate triplet for your platform (e.g.,
x64-linux,x64-windows, orarm64-osx).vcpkg install --triplet x64-linuxUse FTXUI as a Nix Flake dependency
mainTo use FTXUI as a dependency in your own Nix Flake project, add it to your
inputsand then reference the package in youroutputs.- Add the input:
{ inputs.ftxui.url = "github:ArthurSonzogni/FTXUI"; }- Reference the package in your outputs using the pattern
ftxui.packages.<system>.ftxui.
Install FTXUI on Arch Linux via AUR
mainFTXUI is available in the Arch User Repository (AUR). You can install it using an AUR helper like
yay, or by manually downloading the PKGBUILD from the AUR website.yay -S ftxuiBuild and run an FTXUI project with Vcpkg and CMake
mainWhen configuring your project with CMake, you must pass the
CMAKE_TOOLCHAIN_FILEpointing to your vcpkg installation path to ensure the dependencies are found.cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build build ./build/main