FTXUI 7.0.3
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 Loop 是 Component 與 App 的包裝。
13/// 它用於在終端機中執行一個 Component。
14/// @see Component, App.
15/// @see App::Loop().
16/// @see App::Exit().
17/// @param[in] screen 要使用的畫面。
18/// @param[in] component 要執行的元件。
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 迴圈是否已結束。
30bool Loop::HasQuitted() {
31 return screen_->HasQuitted();
32}
33
34/// @brief 執行迴圈。讓 `component` 處理所有待處理的任務/事件。
35/// 如果前一個影格失效,可能會繪製一個新影格。
36/// 在迴圈完成之前返回 true。
37void Loop::RunOnce() {
38 screen_->RunOnce(component_);
39}
40
41/// @brief 等待至少一個事件被處理並執行
42/// `Loop::RunOnce()`。
43void Loop::RunOnceBlocking() {
44 screen_->RunOnceBlocking(component_);
45}
46
47/// 執行迴圈,阻塞目前的執行緒,直到迴圈
48/// 結束為止。
49void Loop::Run() {
50 while (!HasQuitted()) {
51 RunOnceBlocking();
52 }
53}
54
55} // namespace ftxui
FTXUI ftxui:: 命名空間
Definition animation.hpp:11
std::shared_ptr< ComponentBase > Component
Definition app.hpp:23