FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
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/// @see Component, ScreenInteractive.
15/// @see ScreenInteractive::Loop().
16/// @see ScreenInteractive::ExitLoop().
17/// @param[in] screen The screen to use.
18/// @param[in] component The component to run.
19// NOLINTNEXTLINE
21 : screen_(screen), component_(std::move(component)) {
22 screen_->PreMain();
23}
24
26 screen_->PostMain();
27}
28
29/// @brief Whether the loop has quitted.
31 return screen_->HasQuitted();
32}
33
34/// @brief Execute the loop. Make the `component` to process every pending
35/// tasks/events. A new frame might be drawn if the previous was invalidated.
36/// Return true until the loop hasn't completed.
38 screen_->RunOnce(component_);
39}
40
41/// @brief Wait for at least one event to be handled and execute
42/// `Loop::RunOnce()`.
44 screen_->RunOnceBlocking(component_);
45}
46
47/// Execute the loop, blocking the current thread, up until the loop has
48/// quitted.
49void Loop::Run() {
50 while (!HasQuitted()) {
52 }
53}
54
55} // namespace ftxui
bool HasQuitted()
Whether the loop has quitted.
Definition loop.cpp:30
void Run()
Definition loop.cpp:49
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:20
void RunOnce()
Execute the loop. Make the component to process every pending tasks/events. A new frame might be draw...
Definition loop.cpp:37
void RunOnceBlocking()
Wait for at least one event to be handled and execute Loop::RunOnce().
Definition loop.cpp:43
ScreenInteractive is a Screen that can handle events, run a main loop, and manage components.
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
std::shared_ptr< ComponentBase > Component