#include <stdlib.h>
#include <chrono>
#include <memory>
#include <string>
#include <thread>
auto screen = ScreenInteractive::FitComponent();
int custom_loop_count = 0;
int frame_count = 0;
int event_count = 0;
auto component = Renderer([&] {
frame_count++;
return vbox({
text("これはカスタムftxui::Loopの使用例です。これは、"),
text("毎秒100回のイテレーションで実行されます。FTXUIイベントは、"),
text("イテレーションごとに一度すべて処理され、新しいフレームが"),
text("必要に応じてレンダリングされます"),
separator(),
text("ftxui event count: " + std::to_string(event_count)),
text("ftxui frame count: " + std::to_string(frame_count)),
text("Custom loop count: " + std::to_string(custom_loop_count)),
}) |
border;
});
component |= CatchEvent([&](
Event) ->
bool {
event_count++;
return false;
});
Loop loop(&screen, component);
while (!loop.HasQuitted()) {
custom_loop_count++;
loop.RunOnce();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
return EXIT_SUCCESS;
}
Loopは、コンポーネントのイベントループを管理するクラスです。
イベントを表します。キープレスイベント、ターミナルのリサイズなど、さまざまなイベントがあります。