FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
C++20 Modules
Warning
This feature is still in development, and the API may change in future releases. Your contribution is needed to help us improve the compatibility and usability of C++ modules in FTXUI. If you encounter any issues or have suggestions, please open an issue.

FTXUI experimentally supports C++20 modules to reduce compilation times and improve code organization. Each part of the library has a corresponding module, split into partitions per each header.

Use the FTXUI_BUILD_MODULES option to build the FTXUI project itself to provide C++20 modules, for example with CMake and Ninja:

cmake \
-DCMAKE_GENERATOR=Ninja \
-DFTXUI_BUILD_MODULES=ON \
..
ninja
Note
To use modules, you need a C++≥20 compatible compiler, CMake version 3.20 or higher, and use a compatible generator like Ninja. Note that Makefile generators do not support modules.

Then, in your own code you can consume the modules and code as normal:

import ftxui;
using ftxui::App;
using ftxui::Button;
int main() {
App app = App::TerminalOutput();
Component button = Button("Click me", app.ExitLoopClosure());
screen.Loop(button);
return 0;
}
App is a Screen that can handle events, run a main loop, and manage components.
Definition app.hpp:36
Module file re-exporting all FTXUI submodules.
std::shared_ptr< ComponentBase > Component
Definition app.hpp:24

Writing import ftxui; is equivalent to including all <ftxui/**/*.hpp> headers, and provides the entire library through the singular module.

To properly find and link the modules with CMake, use target_link_libraries to get the right compiler, linker, etc. flags.

target_link_libraries(my_executable
#...whatever...
PRIVATE ftxui::modules
)

Module list

While import ftxui; provides the entire library, FTXUI is designed in layers. If you only need specific functionalities, you can import the independent modules directly:

  • ftxui (Convenience module that re-exports all of the below)
    • ftxui.component (Interactive components, events, and event loops)
    • ftxui.dom (Layout and styling via Elements)
    • ftxui.screen (Terminal rendering, pixels, and colors)
    • ftxui.util (Internal utilities)

For example:

import ftxui.screen;
import ftxui.dom;
// Use only screen and dom functionalities...
Module file for FTXUI DOM operations.
Module file for FTXUI screen operations.