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/app.hpp" // for App, Component
9
10namespace ftxui {
11
12/// @brief A Loop is a wrapper around a Component and an App.
13/// It is used to run a Component in a terminal.
14/// @see Component, App.
15/// @see App::Loop().
16/// @see App::Exit().
17/// @param[in] screen The screen to use.
18/// @param[in] component The component to run.
19// NOLINTNEXTLINE
20Loop::Loop(App* screen, Component component)
21 : screen_(screen), component_(std::move(component)) {
22 screen_->PreMain();
23}
24
25Loop::~Loop() {
26 screen_->PostMain();
27}
28
29/// @brief Whether the loop has quit.
30bool 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.
37void Loop::RunOnce() {
38 screen_->RunOnce(component_);
39}
40
41/// @brief Wait for at least one event to be handled and execute
42/// `Loop::RunOnce()`.
43void Loop::RunOnceBlocking() {
44 screen_->RunOnceBlocking(component_);
45}
46
47/// Execute the loop, blocking the current thread, up until the loop has
48/// quit.
49void Loop::Run() {
50 while (!HasQuitted()) {
51 RunOnceBlocking();
52 }
53}
54
55} // namespace ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:11
std::shared_ptr< ComponentBase > Component
Definition app.hpp:23