Skip to content
You are viewing documentation for v7.0.3. Switch to latest (main).

ftxui::App ​

cpp
#include <ftxui/component/app.hpp>

Inherits from: ftxui::Screen

App is a class that manages the application lifecycle. It is responsible for initializing the terminal, running the main loop, and cleaning up on exit.

Note

This class was previously named ScreenInteractive.

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/checkbox, component/checkbox_in_frame, component/collapsible, component/composition, component/custom_loop, component/dropdown, component/dropdown_custom (+40 more)

Summary ​

SymbolDescription
Private
FixedSizeCreate an App with a fixed size.
FullscreenCreate an App taking the full terminal size. This is using the alternate screen buffer to avoid messing with the terminal content.
FullscreenPrimaryScreenCreate an App taking the full terminal size. The primary screen buffer is being used. It means if the terminal is resized, the previous content might mess up with the terminal content.
FullscreenAlternateScreenCreate an App taking the full terminal size. This is using the alternate screen buffer to avoid messing with the terminal content.
FitComponentCreate an App whose width and height match the component being drawn.
TerminalOutputCreate an App whose width match the terminal output width and the height matches the component being drawn.
ActiveReturn the currently active app, nullptr if none.
PostEventOrExecuteAdd a task to the main loop. It will be executed later, after every other scheduled tasks.
~App
App
operator=
TrackMouseSet whether mouse is tracked and events reported.
HandlePipedInputEnable or disable automatic piped input handling. When enabled, FTXUI will detect piped input and redirect stdin from /dev/tty for keyboard input, allowing applications to read piped data while still receiving interactive keyboard events.
LoopExecute the main loop.
ExitExit the main loop.
ExitLoopClosureReturn a function to exit the main loop.
WithRestoredIODecorate a function. The outputted one will execute similarly to the inputted one, but with the currently active app terminal hooks temporarily uninstalled.
ForceHandleCtrlCFTXUI implements handlers for Ctrl-C and Ctrl-Z. By default, these handlers are executed, even if the component catches the event. This avoid users handling every event to be trapped in the application. However, in some cases, the application may want to handle these events itself. In this case, the application can force FTXUI to not handle these events by calling the following functions with force=true.
ForceHandleCtrlZForce FTXUI to handle or not handle Ctrl-Z, even if the component catches the Event::CtrlZ.
PostAdd a task to the main loop. It will be executed later, after every other scheduled tasks.
PostEventAdd an event to the main loop. It will be executed later, after every other scheduled events.
RequestAnimationFrameAdd a task to draw the screen one more time, until all the animations are done.
CaptureMouseTry to get the unique lock about being able to capture the mouse.
GetSelectionReturns the content of the current selection.
SelectionChangeSet a callback that will be called when the selection changes.
TerminalNameReturn the terminal name.
TerminalVersionReturn the terminal version.
TerminalEmulatorNameReturn the terminal emulator name.
TerminalEmulatorVersionReturn the terminal emulator version.
TerminalCapabilitiesReturn the terminal capabilities.
TerminalCapabilityNamesReturn the names of the terminal capabilities.

Public Attributes ​

Private ​

cpp
friend Private;

Static Functions ​

FixedSize ​

cpp
static App FixedSize(int dimx, int dimy);

Create an App with a fixed size.

Parameters:

  • dimx: The width of the app.
  • dimy: The height of the app.

Fullscreen ​

cpp
static App Fullscreen();

Create an App taking the full terminal size. This is using the alternate screen buffer to avoid messing with the terminal content.

Note

This is the same as App::FullscreenAlternateScreen()

FullscreenPrimaryScreen ​

Create an App taking the full terminal size. The primary screen buffer is being used. It means if the terminal is resized, the previous content might mess up with the terminal content.

FullscreenAlternateScreen ​

Create an App taking the full terminal size. This is using the alternate screen buffer to avoid messing with the terminal content.

FitComponent ​

cpp
static App FitComponent();

Create an App whose width and height match the component being drawn.

TerminalOutput ​

cpp
static App TerminalOutput();

Create an App whose width match the terminal output width and the height matches the component being drawn.

Active ​

cpp
static App * Active();

Return the currently active app, nullptr if none.

PostEventOrExecute ​

cpp
static void PostEventOrExecute(Closure closure);

Add a task to the main loop. It will be executed later, after every other scheduled tasks.

Public Member Functions ​

~App ​

cpp
~App();

App ​

cpp
App(App &&);

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/checkbox, component/checkbox_in_frame, component/collapsible, component/composition, component/custom_loop, component/dropdown, component/dropdown_custom (+40 more)

operator= ​

cpp
App & operator=(App &&);

App ​

cpp
App(const App &);

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/checkbox, component/checkbox_in_frame, component/collapsible, component/composition, component/custom_loop, component/dropdown, component/dropdown_custom (+40 more)

operator= ​

cpp
App & operator=(const App &);

TrackMouse ​

cpp
void TrackMouse(bool enable = true);

Set whether mouse is tracked and events reported.

Parameters:

  • enable: Whether to enable mouse event tracking.

Note

Mouse tracking is enabled by default.

Note

Mouse tracking is only supported on terminals that supports it.

Note

This must be called before calling App::Loop.

HandlePipedInput ​

cpp
void HandlePipedInput(bool enable = true);

Enable or disable automatic piped input handling. When enabled, FTXUI will detect piped input and redirect stdin from /dev/tty for keyboard input, allowing applications to read piped data while still receiving interactive keyboard events.

Parameters:

  • enable: Whether to enable piped input handling. Default is true.

Note

This must be called before Loop().

Note

This feature is enabled by default.

Note

This feature is only available on POSIX systems (Linux/macOS).

Loop ​

cpp
void Loop(Component component);

Execute the main loop.

Parameters:

  • component: The component to draw.

Examples: component/button, component/button_animated, component/button_in_frame, component/button_style, component/canvas_animated, component/checkbox, component/checkbox_in_frame, component/collapsible, component/composition, component/custom_loop, component/dropdown, component/dropdown_custom (+40 more)

Exit ​

cpp
void Exit();

Exit the main loop.

ExitLoopClosure ​

cpp
Closure ExitLoopClosure();

Return a function to exit the main loop.

WithRestoredIO ​

cpp
Closure WithRestoredIO(Closure fn);

Decorate a function. The outputted one will execute similarly to the inputted one, but with the currently active app terminal hooks temporarily uninstalled.

ForceHandleCtrlC ​

cpp
void ForceHandleCtrlC(bool force = true);

FTXUI implements handlers for Ctrl-C and Ctrl-Z. By default, these handlers are executed, even if the component catches the event. This avoid users handling every event to be trapped in the application. However, in some cases, the application may want to handle these events itself. In this case, the application can force FTXUI to not handle these events by calling the following functions with force=true.

ForceHandleCtrlZ ​

cpp
void ForceHandleCtrlZ(bool force = true);

Force FTXUI to handle or not handle Ctrl-Z, even if the component catches the Event::CtrlZ.

Post ​

cpp
void Post(Task task);

Add a task to the main loop. It will be executed later, after every other scheduled tasks.

PostEvent ​

cpp
void PostEvent(Event event);

Add an event to the main loop. It will be executed later, after every other scheduled events.

RequestAnimationFrame ​

Add a task to draw the screen one more time, until all the animations are done.

Examples: component/homescreen, component/terminal_info

CaptureMouse ​

cpp
CapturedMouse CaptureMouse();

Try to get the unique lock about being able to capture the mouse.

Returns: A unique lock if the mouse is not already captured, otherwise a null.

GetSelection ​

cpp
std::string GetSelection();

Returns the content of the current selection.

SelectionChange ​

cpp
void SelectionChange(std::function< void()> callback);

Set a callback that will be called when the selection changes.

TerminalName ​

cpp
const std::string & TerminalName() const;

Return the terminal name.

TerminalVersion ​

cpp
int TerminalVersion() const;

Return the terminal version.

TerminalEmulatorName ​

cpp
const std::string & TerminalEmulatorName() const;

Return the terminal emulator name.

TerminalEmulatorVersion ​

cpp
const std::string & TerminalEmulatorVersion() const;

Return the terminal emulator version.

TerminalCapabilities ​

cpp
const std::vector< int > & TerminalCapabilities() const;

Return the terminal capabilities.

TerminalCapabilityNames ​

cpp
std::vector< std::string > TerminalCapabilityNames() const;

Return the names of the terminal capabilities.