FTXUI  5.0.0
C++ functional terminal UI.
loop.cpp
Go to the documentation of this file.
1// Copyright 2022 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
5
6#include <utility> // for move
7
8#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive, Component
9
10namespace ftxui {
11
12/// @brief A Loop is a wrapper around a Component and a ScreenInteractive.
13/// It is used to run a Component in a terminal.
14/// @ingroup component
15/// @see Component, ScreenInteractive.
16/// @see ScreenInteractive::Loop().
17/// @see ScreenInteractive::ExitLoop().
18/// @param screen The screen to use.
19/// @param component The component to run.
20// NOLINTNEXTLINE
22 : screen_(screen), component_(std::move(component)) {
23 screen_->PreMain();
24}
25
27 screen_->PostMain();
28}
29
30/// @brief Whether the loop has quitted.
31/// @ingroup component
33 return screen_->HasQuitted();
34}
35
36/// @brief Execute the loop. Make the `component` to process every pending
37/// tasks/events. A new frame might be drawn if the previous was invalidated.
38/// Return true until the loop hasn't completed.
40 screen_->RunOnce(component_);
41}
42
43/// @brief Wait for at least one event to be handled and execute
44/// `Loop::RunOnce()`.
46 screen_->RunOnceBlocking(component_);
47}
48
49/// Execute the loop, blocking the current thread, up until the loop has
50/// quitted.
51void Loop::Run() {
52 while (!HasQuitted()) {
54 }
55}
56
57} // namespace ftxui
bool HasQuitted()
Whether the loop has quitted.
Definition: loop.cpp:32
void Run()
Definition: loop.cpp:51
Loop(ScreenInteractive *screen, Component component)
A Loop is a wrapper around a Component and a ScreenInteractive. It is used to run a Component in a te...
Definition: loop.cpp:21
void RunOnce()
Execute the loop. Make the component to process every pending tasks/events. A new frame might be draw...
Definition: loop.cpp:39
void RunOnceBlocking()
Wait for at least one event to be handled and execute Loop::RunOnce().
Definition: loop.cpp:45
std::shared_ptr< ComponentBase > Component