FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
custom_loop.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. 全著作権所有。
2// このソースコードの使用は、LICENSEファイルにあるMITライセンスに従います。
3#include <stdlib.h> // for EXIT_SUCCESS
4#include <chrono> // for milliseconds
5#include <ftxui/component/event.hpp> // for Event
6#include <ftxui/component/mouse.hpp> // for ftxui
7#include <ftxui/dom/elements.hpp> // for text, separator, Element, operator|, vbox, border
8#include <memory> // for allocator, shared_ptr
9#include <string> // for operator+, to_string
10#include <thread> // for sleep_for
11
12#include "ftxui/component/component.hpp" // for CatchEvent, Renderer, operator|=
13#include "ftxui/component/loop.hpp" // for Loop
14#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
15
16int main() {
17 using namespace ftxui;
18 auto screen = ScreenInteractive::FitComponent();
19
20 // 描画されたフレーム数と処理されたイベント数を数えるコンポーネントを作成します。
21 int custom_loop_count = 0;
22 int frame_count = 0;
23 int event_count = 0;
24 auto component = Renderer([&] {
25 frame_count++;
26 return vbox({
27 text("これはカスタムftxui::Loopの使用例です。これは、"),
28 text("毎秒100回のイテレーションで実行されます。FTXUIイベントは、"),
29 text("イテレーションごとに一度すべて処理され、新しいフレームが"),
30 text("必要に応じてレンダリングされます"),
31 separator(),
32 text("ftxui event count: " + std::to_string(event_count)),
33 text("ftxui frame count: " + std::to_string(frame_count)),
34 text("Custom loop count: " + std::to_string(custom_loop_count)),
35 }) |
36 border;
37 });
38
39 component |= CatchEvent([&](Event) -> bool {
40 event_count++;
41 return false;
42 });
43
44 Loop loop(&screen, component);
45
46 while (!loop.HasQuitted()) {
47 custom_loop_count++;
48 loop.RunOnce();
49 std::this_thread::sleep_for(std::chrono::milliseconds(10));
50 }
51
52 return EXIT_SUCCESS;
53}
int main()
Loopは、コンポーネントのイベントループを管理するクラスです。
Definition loop.hpp:53
イベントを表します。キープレスイベント、ターミナルのリサイズなど、さまざまなイベントがあります。
Definition event.hpp:28
FTXUI ftxui:: 名前空間
Definition animation.hpp:9