FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
screen_interactive.hpp
Go to the documentation of this file.
1// Copyright 2020 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_SCREEN_INTERACTIVE_HPP
5#define FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP
6
7#include <atomic> // for atomic
8#include <functional> // for function
9#include <memory> // for shared_ptr
10#include <string> // for string
11
12#include "ftxui/component/animation.hpp" // for TimePoint
13#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
14#include "ftxui/component/event.hpp" // for Event
15#include "ftxui/component/task.hpp" // for Task, Closure
16#include "ftxui/dom/selection.hpp" // for SelectionOption
17#include "ftxui/screen/screen.hpp" // for Screen
18
19namespace ftxui {
20class ComponentBase;
21class Loop;
22struct Event;
23
24using Component = std::shared_ptr<ComponentBase>;
25class ScreenInteractivePrivate;
26
27namespace task {
28class TaskRunner;
29}
30
31/// @brief ScreenInteractive はイベントを処理し、メインループを実行し、コンポーネントを管理できる `Screen` です。
32///
33/// @ingroup component
34class ScreenInteractive : public Screen {
35 public:
36 // Constructors:
37 static ScreenInteractive FixedSize(int dimx, int dimy);
43
44 // Destructor.
46
47 // オプション。Loop() の前に呼び出す必要があります。
48 void TrackMouse(bool enable = true);
49 void HandlePipedInput(bool enable = true);
50
51 // 現在アクティブなスクリーンを返します。アクティブなスクリーンがない場合は nullptr を返します。
52 static ScreenInteractive* Active();
53
54 // メインループを開始/停止します。
55 void Loop(Component);
56 void Exit();
58
59 // ループによって実行されるタスクを投稿します。
60 void Post(Task task);
61 void PostEvent(Event event);
63
65
66 // 関数を装飾します。出力された関数は入力された関数と同様に実行されますが、
67 // 現在アクティブなスクリーンターミナルフックは一時的にアンインストールされます。
69
70 // FTXUI は Ctrl-C および Ctrl-Z のハンドラを実装しています。デフォルトでは、これらのハンドラは
71 // コンポーネントがイベントをキャッチした場合でも実行されます。これにより、ユーザーが
72 // すべてのイベントを処理してアプリケーションに閉じ込められることを回避します。ただし、場合によっては
73 // アプリケーションがこれらのイベント自体を処理したい場合があります。この場合、
74 // アプリケーションは以下の関数を force=true で呼び出すことで、FTXUI がこれらのイベントを処理しないように強制できます。
75 void ForceHandleCtrlC(bool force);
76 void ForceHandleCtrlZ(bool force);
77
78 // 選択 API。
79 std::string GetSelection();
80 void SelectionChange(std::function<void()> callback);
81
82 private:
83 void ExitNow();
84
85 void Install();
86 void Uninstall();
87
88 void PreMain();
89 void PostMain();
90
91 bool HasQuitted();
92 void RunOnce(Component component);
93 void RunOnceBlocking(Component component);
94
95 void HandleTask(Component component, Task& task);
96 bool HandleSelection(bool handled, Event event);
97 void RefreshSelection();
98 void Draw(Component component);
99 void ResetCursorPosition();
100
101 void InstallPipedInputHandling();
102
103 void Signal(int signal);
104
105 void FetchTerminalEvents();
106
107 void PostAnimationTask();
108
109 ScreenInteractive* suspended_screen_ = nullptr;
110 enum class Dimension {
112 Fixed,
115 };
117 int dimx,
118 int dimy,
119 bool use_alternative_screen);
120
121 const Dimension dimension_;
122 const bool use_alternative_screen_;
123
124 bool track_mouse_ = true;
125
126 std::string set_cursor_position;
127 std::string reset_cursor_position;
128
129 std::atomic<bool> quit_{false};
130 bool animation_requested_ = false;
131 animation::TimePoint previous_animation_time_;
132
133 int cursor_x_ = 1;
134 int cursor_y_ = 1;
135
136 std::uint64_t frame_count_ = 0;
137 bool mouse_captured = false;
138 bool previous_frame_resized_ = false;
139
140 bool frame_valid_ = false;
141
142 bool force_handle_ctrl_c_ = true;
143 bool force_handle_ctrl_z_ = true;
144
145 // パイプ入力処理の状態 (POSIX のみ)
146 bool handle_piped_input_ = true;
147 // /dev/tty のファイル記述子。パイプ入力処理に使用されます。
148 int tty_fd_ = -1;
149
150 // 終了時に復元するカーソルのスタイル。
151 int cursor_reset_shape_ = 1;
152
153 // 選択 API:
154 CapturedMouse selection_pending_;
155 struct SelectionData {
156 int start_x = -1;
157 int start_y = -1;
158 int end_x = -2;
159 int end_y = -2;
160 bool empty = true;
161 bool operator==(const SelectionData& other) const;
162 bool operator!=(const SelectionData& other) const;
163 };
164 SelectionData selection_data_;
165 SelectionData selection_data_previous_;
166 std::unique_ptr<Selection> selection_;
167 std::function<void()> selection_on_change_;
168
169 // PIMPL (Private Implementation) イディオム。
170 struct Internal;
171 std::unique_ptr<Internal> internal_;
172
173 friend class Loop;
174
175 Component component_;
176
177 public:
178 class Private {
179 public:
180 static void Signal(ScreenInteractive& s, int signal) { s.Signal(signal); }
181 };
182 friend Private;
183};
184
185} // namespace ftxui
186
187#endif /* end of include guard: FTXUI_COMPONENT_SCREEN_INTERACTIVE_HPP */
static void Signal(ScreenInteractive &s, int signal)
static ScreenInteractive TerminalOutput()
ターミナル出力の幅に一致し、描画されるコンポーネントの高さに一致するScreenInteractiveを作成します。
void HandlePipedInput(bool enable=true)
自動パイプ入力処理を有効または無効にします。 有効にすると、FTXUIはパイプ入力を検出し、キーボード入力のためにstdinを/dev/ttyからリダイレクトし、アプリケーションがパイプデータを読み取り...
void Exit()
メインループを終了します。
static ScreenInteractive FixedSize(int dimx, int dimy)
void PostEvent(Event event)
メインループにイベントを追加します。 これは、他のすべてのスケジュールされたイベントの後に実行されます。
void Post(Task task)
メインループにタスクを追加します。 これは、他のすべてのスケジュールされたタスクの後に実行されます。
static ScreenInteractive FitComponent()
描画されるコンポーネントの幅と高さに一致するScreenInteractiveを作成します。
static ScreenInteractive Fullscreen()
static ScreenInteractive FullscreenPrimaryScreen()
ターミナルサイズの全体を使用するScreenInteractiveを作成します。プライマリスクリーンバッファが使用されます。これは、ターミナルがリサイズされた場合、以前のコンテンツがターミナルコンテンツ...
static ScreenInteractive * Active()
現在アクティブな画面を返します。アクティブな画面がない場合はヌルを返します。
CapturedMouse CaptureMouse()
マウスをキャプチャできることに関するユニークロックを取得しようとします。
std::string GetSelection()
現在の選択内容を返します
static ScreenInteractive FullscreenAlternateScreen()
ターミナルサイズの全体を使用するScreenInteractiveを作成します。これは、ターミナルコンテンツを乱すことを避けるために、代替スクリーンバッファを使用します。
void TrackMouse(bool enable=true)
マウスが追跡され、イベントが報告されるかどうかを設定します。 メインループの外側で呼び出されます。例: ScreenInteractive::Loop(...)。
void SelectionChange(std::function< void()> callback)
void RequestAnimationFrame()
すべてのアニメーションが完了するまで、画面をもう一度描画するタスクを追加します。
Closure ExitLoopClosure()
メインループを終了する関数を返します。
void ForceHandleCtrlC(bool force)
コンポーネントがEvent::CtrlCをキャッチした場合でも、FTXUIにCtrl-Cを処理させるか処理させないかを強制します。
void ForceHandleCtrlZ(bool force)
コンポーネントがEvent::CtrlZをキャッチした場合でも、FTXUIにCtrl-Zを処理させるか処理させないかを強制します。
Closure WithRestoredIO(Closure)
関数を装飾します。それは同じように実行されますが、実行中に現在アクティブなスクリーンターミナルフックは一時的にアンインストールされます。
Loopは、コンポーネントのイベントループを管理するクラスです。
Definition loop.hpp:53
ScreenInteractive はイベントを処理し、メインループを実行し、コンポーネントを管理できる Screen です。
イベントを表します。キープレスイベント、ターミナルのリサイズなど、さまざまなイベントがあります。
Definition event.hpp:28
int dimy() const
Definition image.hpp:36
int dimx() const
Definition image.hpp:35
ピクセルの長方形グリッド。
Definition screen.hpp:25
FTXUI ftxui::Dimension::名前空間
std::chrono::time_point< Clock > TimePoint
Definition animation.hpp:23
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::variant< Event, Closure, AnimationTask > Task
Definition task.hpp:13
std::function< void()> Closure
Definition task.hpp:12
std::shared_ptr< ComponentBase > Component