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

ftxui::Loop ​

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

Loop is a class that manages the event loop for a component.

It is responsible for running the component, handling events, and updating the screen.

The Loop class is designed to be used with an App object, which represents the terminal screen.

Example

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

int main() {
 auto screen = ftxui::App::TerminalOutput();
 auto component = ftxui::Button("Click me", [] { ... });

ftxui::Loop loop(screen.get(), component);

// Either
 loop.Run();  // Blocking until the component quits.

// Or
 loop.RunOnce();  // Non-blocking, returns immediately.

// Or
 loop.RunOnceBlocking();  // Blocking until handling one event.

// Or in a loop:
 while (!loop.HasQuitted()) {
   loop.RunOnce();

// Do something else like running a different library loop function.
 }
}

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
LoopA Loop is a wrapper around a Component and an App. It is used to run a Component in a terminal.
~Loop
HasQuittedWhether the loop has quit.
RunOnceExecute the loop. Make the component to process every pending tasks/events. A new frame might be drawn if the previous was invalidated. Return true until the loop hasn't completed.
RunOnceBlockingWait for at least one event to be handled and execute Loop::RunOnce().
RunExecute the loop, blocking the current thread, up until the loop has quit.
operator=

Public Member Functions ​

Loop ​

cpp
Loop(App * screen, Component component);

A Loop is a wrapper around a Component and an App. It is used to run a Component in a terminal.

See also: Component, App., App::Loop(), App::Exit().

Parameters:

  • screen: The screen to use.
  • component: The component to run.

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)

~Loop ​

cpp
~Loop();

HasQuitted ​

cpp
bool HasQuitted();

Whether the loop has quit.

RunOnce ​

cpp
void RunOnce();

Execute the loop. Make the component to process every pending tasks/events. A new frame might be drawn if the previous was invalidated. Return true until the loop hasn't completed.

RunOnceBlocking ​

cpp
void RunOnceBlocking();

Wait for at least one event to be handled and execute Loop::RunOnce().

Run ​

cpp
void Run();

Execute the loop, blocking the current thread, up until the loop has quit.

operator= ​

cpp
Loop & operator=(Loop &&);

operator= ​

cpp
Loop & operator=(const Loop &);

Loop ​

cpp
Loop(Loop &&);

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)

Loop ​

cpp
Loop(const Loop &);

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)