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.
4#include "ftxui/component/loop.hpp"
5
6#include <utility> // for move
7
8#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive, Component
9
10 namespace 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
20 Loop::Loop(ScreenInteractive* screen, Component component)
21 : screen_(screen), component_(std::move(component)) {
22 screen_->PreMain();
23}
24
25 Loop::~Loop() {
26 screen_->PostMain();
27}
28
29/// @brief Whether the loop has quitted.
30 bool Loop::HasQuitted() {
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.
37 void Loop::RunOnce() {
38 screen_->RunOnce(component_);
39}
40
41/// @brief Wait for at least one event to be handled and execute
42/// `Loop::RunOnce()`.
43 void Loop::RunOnceBlocking() {
44 screen_->RunOnceBlocking(component_);
45}
46
47/// Execute the loop, blocking the current thread, up until the loop has
48/// quitted.
49 void Loop::Run() {
50 while (!HasQuitted()) {
51 RunOnceBlocking();
52 }
53}
54
55} // namespace ftxui
ftxui::Loop::HasQuitted
bool HasQuitted()
Whether the loop has quitted.
Definition loop.cpp:30
ftxui::Loop::~Loop
~Loop()
Definition loop.cpp:25
ftxui::Loop::Run
void Run()
Definition loop.cpp:49
ftxui::Loop::Loop
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
ftxui::Loop::RunOnce
void RunOnce()
Execute the loop. Make the component to process every pending tasks/events. A new frame might be draw...
Definition loop.cpp:37
ftxui::Loop::RunOnceBlocking
void RunOnceBlocking()
Wait for at least one event to be handled and execute Loop::RunOnce().
Definition loop.cpp:43
ftxui::ScreenInteractive
ScreenInteractive is a Screen that can handle events, run a main loop, and manage components.
Definition screen_interactive.hpp:33
loop.hpp
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::Component
std::shared_ptr< ComponentBase > Component
Definition component_base.hpp:24
screen_interactive.hpp