FTXUI
5.0.0
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
/// @ingroup component
15
/// @see Component, ScreenInteractive.
16
/// @see ScreenInteractive::Loop().
17
/// @see ScreenInteractive::ExitLoop().
18
/// @param[in] screen The screen to use.
19
/// @param[in] component The component to run.
20
// NOLINTNEXTLINE
21
Loop::Loop
(
ScreenInteractive
*
screen
,
Component
component
)
22
: screen_(
screen
), component_(
std
::
move
(
component
)) {
23
screen_->PreMain();
24
}
25
26
Loop::~Loop
() {
27
screen_->PostMain();
28
}
29
30
/// @brief Whether the loop has quitted.
31
/// @ingroup component
32
bool
Loop::HasQuitted
() {
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.
39
void
Loop::RunOnce
() {
40
screen_->RunOnce(component_);
41
}
42
43
/// @brief Wait for at least one event to be handled and execute
44
/// `Loop::RunOnce()`.
45
void
Loop::RunOnceBlocking
() {
46
screen_->RunOnceBlocking(component_);
47
}
48
49
/// Execute the loop, blocking the current thread, up until the loop has
50
/// quitted.
51
void
Loop::Run
() {
52
while
(!
HasQuitted
()) {
53
RunOnceBlocking
();
54
}
55
}
56
57
}
// namespace ftxui
ftxui::Loop::HasQuitted
bool HasQuitted()
Whether the loop has quitted.
Definition
loop.cpp:32
ftxui::Loop::~Loop
~Loop()
Definition
loop.cpp:26
ftxui::Loop::Run
void Run()
Definition
loop.cpp:51
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:21
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:39
ftxui::Loop::RunOnceBlocking
void RunOnceBlocking()
Wait for at least one event to be handled and execute Loop::RunOnce().
Definition
loop.cpp:45
ftxui::ScreenInteractive
Definition
screen_interactive.hpp:29
loop.hpp
ftxui
Definition
animation.hpp:10
ftxui::Make
std::shared_ptr< T > Make(Args &&... args)
Definition
component.hpp:26
ftxui::Component
std::shared_ptr< ComponentBase > Component
Definition
component_base.hpp:24
screen_interactive.hpp