FTXUI 6.1.9
C++ functional terminal UI.
|
The ftxui::screen
module is the low-level foundation. It can be used standalone, but it is primarily designed to be used together by ftxui::dom and ftxui::component modules.
It provides a ftxui::Screen.
The ftxui::Screen class represents a 2D grid of styled characters that can be rendered to a terminal.
It provides methods to create a screen, access pixels, and render elements.
You can access the individual cells (ftxui::Pixel) of the screen using the ftxui::Screen::PixelAt method, which returns a reference to the pixel at the specified coordinates.
Example
The screen can be printed to the terminal using ftxui::Screen::Print() or converted to a std::string with ftxui::Screen::ToString().
Note that you can reset the cursor position to the top-left corner of the screen after printing by calling ftxui::Screen::ResetCursorPosition().
Example
The ftxui::Dimension utility controls screen sizing:
Dimension::Full()
— use full terminal width or heightDimension::Fit(element)
— size to fit the rendered ftxui::ElementDimension::Fixed(n)
— use exactly n
columns or rowsThese values are to be passed to ftxui::Screen::Create()
.
ftxui::Screen::Create() provides two overloads:
Screen::Create(Dimension)
sets both width and height to the same kind of dimensionScreen::Create(Dimension width, Dimension height)
allows distinct control per axisOnce created, render an element and display the result:
Each cell in the screen grid is a ftxui::Pixel, which holds:
character
foreground_color
background_color
blink
bold
dim
italic
inverted
(swap foreground and background colors)underlined
underlined_double
strikethrough
PixelAt(x, y)
performs bounds checking and returns a reference to the pixel at the specified coordinate. If out-of-bounds, a dummy pixel reference is returned.Each cell in the screen is a ftxui::Pixel. You can modify them using:
The ftxui::Color class is used to define foreground and background colors for each ftxui::Pixel.
It supports various color spaces and predefined palettes. FTXUI will dynamically fallback to the closest available color in the terminal if the requested color is not supported by the terminal.
Color Spaces
ftxui::Color::Default
(terminal's default color)