FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
loop.hpp
浏览该文件的文档.
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#ifndef FTXUI_COMPONENT_LOOP_HPP
5#define FTXUI_COMPONENT_LOOP_HPP
6
7#include <memory> // 用于 shared_ptr
8
9/// #include "ftxui/component/component_base.hpp" // 用于 ComponentBase
10
11namespace ftxui {
12class ComponentBase;
13
14using Component = std::shared_ptr<ComponentBase>;
15class ScreenInteractive;
16
17/// @brief Loop 是一个管理组件事件循环的类。
18///
19/// 它负责运行组件、处理事件和更新屏幕。
20///
21/// Loop 类设计用于 ScreenInteractive 对象,
22/// 该对象表示终端屏幕。
23///
24/// **示例**
25/// ```cpp
26/// #include <ftxui/component/component.hpp>
27/// #include <ftxui/component/screen_interactive.hpp>
28/// #include <ftxui/component/loop.hpp>
29///
30/// int main() {
31/// auto screen = ftxui::ScreenInteractive::TerminalOutput();
32/// auto component = ftxui::Button("Click me", [] { ... });
33///
34/// ftxui::Loop loop(screen.get(), component);
35///
36/// // Either
37/// loop.Run(); // Blocking until the component quits.
38///
39/// // Or
40/// loop.RunOnce(); // Non-blocking, returns immediately.
41///
42/// // Or
43/// loop.RunOnceBlocking(); // Blocking until handling one event.
44///
45/// // Or in a loop:
46/// while (!loop.HasQuitted()) {
47/// loop.RunOnce();
48///
49/// // Do something else like running a different library loop function.
50/// }
51/// }
52/// ```
53///
54/// @ingroup component
55class Loop {
56 public:
57 Loop(ScreenInteractive* screen, Component component);
58 ~Loop();
59
60 bool HasQuitted();
61 void RunOnce();
62 void RunOnceBlocking();
63 void Run();
64
65 // 此类不可复制/移动。
66 Loop(const Loop&) = default;
67 Loop(Loop&&) = delete;
68 Loop& operator=(Loop&&) = delete;
69 Loop(const ScreenInteractive&) = delete;
70 Loop& operator=(const Loop&) = delete;
71
72 private:
73 ScreenInteractive* screen_;
74 Component component_;
75};
76
77} // namespace ftxui
78
79#endif // FTXUI_COMPONENT_LOOP_HPP
bool HasQuitted()
循环是否已退出。
Loop(const ScreenInteractive &)=delete
void Run()
执行循环,阻塞当前线程,直到循环退出。
Loop(ScreenInteractive *screen, Component component)
Loop 是 Component 和 ScreenInteractive 的包装器。 它用于在终端中运行 Component。
Loop & operator=(const Loop &)=delete
void RunOnce()
执行循环。使 component 处理所有待处理的任务/事件。 如果前一帧无效,可能会绘制新帧。 在循环完成之前返回 true。
Loop(const Loop &)=default
Loop & operator=(Loop &&)=delete
Loop(Loop &&)=delete
void RunOnceBlocking()
等待至少一个事件被处理并执行 Loop::RunOnce()。
Loop 是一个管理组件事件循环的类。
ScreenInteractive 是一个可以处理事件、运行主循环和管理组件的 Screen。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::shared_ptr< ComponentBase > Component