ftxui::Loop
#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
#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
| Symbol | Description |
|---|---|
Loop | A Loop is a wrapper around a Component and an App. It is used to run a Component in a terminal. |
~Loop | |
HasQuitted | Whether the loop has quit. |
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 | Wait for at least one event to be handled and execute Loop::RunOnce(). |
Run | Execute the loop, blocking the current thread, up until the loop has quit. |
operator= |
Public Member Functions
Loop
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
~Loop();HasQuitted
bool HasQuitted();Whether the loop has quit.
RunOnce
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
void RunOnceBlocking();Wait for at least one event to be handled and execute Loop::RunOnce().
Run
void Run();Execute the loop, blocking the current thread, up until the loop has quit.
operator=
operator=
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
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)