ftxui::App
#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 (+41 more)
Summary
| Symbol | Description |
|---|---|
Private | |
FixedSize | Create an App with a fixed size. |
Fullscreen | Create an App taking the full terminal size. This is using the alternate screen buffer to avoid messing with the terminal content. |
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 | Create an App whose width and height match the component being drawn. |
TerminalOutput | Create an App whose width match the terminal output width and the height matches the component being drawn. |
Active | Return the currently active app, nullptr if none. |
PostEventOrExecute | Add a task to the main loop. It will be executed later, after every other scheduled tasks. |
~App | |
App | |
operator= | |
TrackMouse | Set whether mouse is tracked and events reported. |
HandlePipedInput | 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. |
Loop | Execute the main loop. |
Exit | Exit the main loop. |
ExitLoopClosure | Return a function to exit the main loop. |
WithRestoredIO | Decorate a function. The outputted one will execute similarly to the inputted one, but with the currently active app terminal hooks temporarily uninstalled. |
ForceHandleCtrlC | 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 | Force FTXUI to handle or not handle Ctrl-Z, even if the component catches the Event::CtrlZ. |
Post | Add a task to the main loop. It will be executed later, after every other scheduled tasks. |
PostEvent | 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. |
PrintAbove | Print an element above the app. It is printed once, and becomes part of the terminal scrollback. The app keeps being drawn below. |
CaptureMouse | Try to get the unique lock about being able to capture the mouse. |
GetSelection | Returns the content of the current selection. |
SelectionChange | Set a callback that will be called when the selection changes. |
TerminalName | Return the terminal name. |
TerminalVersion | Return the terminal version. |
TerminalEmulatorName | Return the terminal emulator name. |
TerminalEmulatorVersion | Return the terminal emulator version. |
TerminalCapabilities | Return the terminal capabilities. |
TerminalCapabilityNames | Return the names of the terminal capabilities. |
Public Attributes
Private
friend Private;Static Functions
FixedSize
Create an App with a fixed size.
Parameters:
dimx: The width of the app.dimy: The height of the app.
Fullscreen
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
static App 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
static App FullscreenAlternateScreen();Create an App taking the full terminal size. This is using the alternate screen buffer to avoid messing with the terminal content.
FitComponent
static App FitComponent();Create an App whose width and height match the component being drawn.
TerminalOutput
static App TerminalOutput();Create an App whose width match the terminal output width and the height matches the component being drawn.
Active
Return the currently active app, nullptr if none.
PostEventOrExecute
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
~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 (+41 more)
operator=
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 (+41 more)
operator=
TrackMouse
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.
HandlePipedInput
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
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 (+41 more)
Exit
void Exit();Exit the main loop.
ExitLoopClosure
Closure ExitLoopClosure();Return a function to exit the main loop.
WithRestoredIO
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
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
void ForceHandleCtrlZ(bool force = true);Force FTXUI to handle or not handle Ctrl-Z, even if the component catches the Event::CtrlZ.
Post
void Post(Task task);Add a task to the main loop. It will be executed later, after every other scheduled tasks.
PostEvent
Add an event to the main loop. It will be executed later, after every other scheduled events.
RequestAnimationFrame
void RequestAnimationFrame();Add a task to draw the screen one more time, until all the animations are done.
Examples: component/homescreen, component/terminal_info
PrintAbove
void PrintAbove(Element element);Print an element above the app. It is printed once, and becomes part of the terminal scrollback. The app keeps being drawn below.
Parameters:
element: The element to print. Its width is the terminal width.
Note
This is meant for apps not using the alternate screen, such as App::TerminalOutput().
CaptureMouse
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
std::string GetSelection();Returns the content of the current selection.
SelectionChange
void SelectionChange(std::function< void()> callback);Set a callback that will be called when the selection changes.
TerminalName
const std::string & TerminalName() const;Return the terminal name.
TerminalVersion
int TerminalVersion() const;Return the terminal version.
TerminalEmulatorName
const std::string & TerminalEmulatorName() const;Return the terminal emulator name.
TerminalEmulatorVersion
const std::string & TerminalEmulatorVersion() const;Return the terminal emulator version.
TerminalCapabilities
const std::vector< int > & TerminalCapabilities() const;Return the terminal capabilities.
TerminalCapabilityNames
std::vector< std::string > TerminalCapabilityNames() const;Return the names of the terminal capabilities.