Skip to content

ftxui::Screen ​

cpp
#include <ftxui/screen/screen.hpp>

Inherits from: ftxui::Surface

Derived classes: ftxui::App

A rectangular grid of Cell.

Examples: dom/border, dom/border_colored, dom/border_style, dom/canvas, dom/color_gallery, dom/color_info_palette256, dom/color_truecolor_HSV, dom/color_truecolor_RGB, dom/dbox, dom/gauge, dom/gauge_direction, dom/graph (+25 more)

Summary ​

SymbolDescription
SelectionStyle
Screen
~Screen
operator=
ToStringProduce a std::string that can be used to print the Screen on the terminal.
Print
ClearClear all the cells from the screen.
ResetPositionReturn a string to be printed in order to reset the cursor position to the beginning of the screen.
ApplyShader
cursor
SetCursor
RegisterHyperlink
Hyperlink
GetSelectionStyleReturn the current selection style.
SetSelectionStyleSet the current selection style.
CreateCreate a screen with the given dimension.

Public Types ​

SelectionStyle ​

cpp
using SelectionStyle = std::function< void(Cell &)>;

Public Member Functions ​

Screen ​

cpp
Screen(int dimx, int dimy);

Examples: dom/border, dom/border_colored, dom/border_style, dom/canvas, dom/color_gallery, dom/color_info_palette256, dom/color_truecolor_HSV, dom/color_truecolor_RGB, dom/dbox, dom/gauge, dom/gauge_direction, dom/graph (+25 more)

~Screen ​

cpp
~Screen();

Screen ​

cpp
Screen(const Screen &);

Examples: dom/border, dom/border_colored, dom/border_style, dom/canvas, dom/color_gallery, dom/color_info_palette256, dom/color_truecolor_HSV, dom/color_truecolor_RGB, dom/dbox, dom/gauge, dom/gauge_direction, dom/graph (+25 more)

operator= ​

cpp
Screen & operator=(const Screen &);

ToString ​

cpp
std::string ToString() const;

Produce a std::string that can be used to print the Screen on the terminal.

Note

Don't forget to flush stdout. Alternatively, you can use Screen::Print();

ToString ​

cpp
void ToString(std::string & ss) const;

Produce a std::string that can be used to print the Screen on the terminal.

Parameters:

  • ss: The string to append to.

ToString ​

cpp
void ToString(std::string & ss, const Screen & previous) const;

Produce a std::string updating the terminal from previous to this Screen. Only the cells that changed are printed.

Parameters:

  • ss: The string to append to.
  • previous: The Screen currently displayed. The cursor must be at its top-left corner. It ends where ToString() would leave it.

Print ​

cpp
void Print() const;

Clear ​

cpp
void Clear();

Clear all the cells from the screen.

ResetPosition ​

cpp
std::string ResetPosition(bool clear = false) const;

Return a string to be printed in order to reset the cursor position to the beginning of the screen.

cpp
std::string reset_position;
while(true) {
  auto document = render();
  auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
  Render(screen, document);
  std::cout << reset_position << screen.ToString() << std::flush;
  reset_position = screen.ResetPosition();

using namespace std::chrono_literals;
  std::this_thread::sleep_for(0.01s);
}

Returns: The string to print in order to reset the cursor position to the beginning.

ResetPosition ​

cpp
void ResetPosition(std::string & ss, bool clear = false) const;

Append to a string in order to reset the cursor position to the beginning of the screen.

Parameters:

  • ss: The string to append to.
  • clear: Whether to clear the screen or not.

ApplyShader ​

cpp
void ApplyShader();

cursor ​

cpp
Cursor cursor() const;

SetCursor ​

cpp
void SetCursor(Cursor cursor);
cpp
uint8_t RegisterHyperlink(std::string_view link);
cpp
const std::string & Hyperlink(uint8_t id) const;

GetSelectionStyle ​

cpp
const SelectionStyle & GetSelectionStyle() const;

Return the current selection style.

See also: SetSelectionStyle

SetSelectionStyle ​

cpp
void SetSelectionStyle(SelectionStyle decorator);

Set the current selection style.

See also: GetSelectionStyle

Static Functions ​

Create ​

cpp
static Screen Create(Dimensions dimension);

Create a screen with the given dimension.

Create ​

cpp
static Screen Create(Dimensions width, Dimensions height);

Create a screen with the given dimension along the x-axis and y-axis.