FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
event.hpp
浏览该文件的文档.
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_EVENT_HPP
5#define FTXUI_COMPONENT_EVENT_HPP
6
7#include <ftxui/component/mouse.hpp> // for Mouse
8#include <string> // for string, operator==
9
10namespace ftxui {
11
12class ScreenInteractive;
13class ComponentBase;
14
15/// @brief 代表一个事件。它可以是按键事件、终端大小调整等等...
16///
17/// 例如:
18/// - 可打印字符可以使用 Event::Character('a') 创建。
19/// - 一些特殊事件是预定义的,例如 Event::ArrowLeft。
20/// - 可以使用以下方法查找特殊事件的任意代码:
21/// ./example/util/print_key_press
22/// 例如,CTRL+A 映射到 Event::Special({1});
23///
24/// 有关 xterm 规范的有用文档:
25/// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
26///
27/// @ingroup component
28struct Event {
29 // --- 构造函数部分 -----------------------------------------------------------
30 static Event Character(std::string);
31 static Event Character(char);
32 static Event Character(wchar_t);
33 static Event Special(std::string);
34 static Event Mouse(std::string, Mouse mouse);
35 static Event CursorPosition(std::string, int x, int y); // 内部
36 static Event CursorShape(std::string, int shape); // 内部
37
38 // --- 箭头键 ---
39 static const Event ArrowLeft;
40 static const Event ArrowRight;
41 static const Event ArrowUp;
42 static const Event ArrowDown;
43
44 static const Event ArrowLeftCtrl;
45 static const Event ArrowRightCtrl;
46 static const Event ArrowUpCtrl;
47 static const Event ArrowDownCtrl;
48
49 // --- 其他 ---
50 static const Event Backspace;
51 static const Event Delete;
52 static const Event Return;
53 static const Event Escape;
54 static const Event Tab;
55 static const Event TabReverse;
56
57 // --- 导航键 ---
58 static const Event Insert;
59 static const Event Home;
60 static const Event End;
61 static const Event PageUp;
62 static const Event PageDown;
63
64 // --- 功能键 ---
65 static const Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
66
67 // --- 控制键 ---
68 static const Event a, A, CtrlA, AltA, CtrlAltA;
69 static const Event b, B, CtrlB, AltB, CtrlAltB;
70 static const Event c, C, CtrlC, AltC, CtrlAltC;
71 static const Event d, D, CtrlD, AltD, CtrlAltD;
72 static const Event e, E, CtrlE, AltE, CtrlAltE;
73 static const Event f, F, CtrlF, AltF, CtrlAltF;
74 static const Event g, G, CtrlG, AltG, CtrlAltG;
75 static const Event h, H, CtrlH, AltH, CtrlAltH;
76 static const Event i, I, CtrlI, AltI, CtrlAltI;
77 static const Event j, J, CtrlJ, AltJ, CtrlAltJ;
78 static const Event k, K, CtrlK, AltK, CtrlAltK;
79 static const Event l, L, CtrlL, AltL, CtrlAltL;
80 static const Event m, M, CtrlM, AltM, CtrlAltM;
81 static const Event n, N, CtrlN, AltN, CtrlAltN;
82 static const Event o, O, CtrlO, AltO, CtrlAltO;
83 static const Event p, P, CtrlP, AltP, CtrlAltP;
84 static const Event q, Q, CtrlQ, AltQ, CtrlAltQ;
85 static const Event r, R, CtrlR, AltR, CtrlAltR;
86 static const Event s, S, CtrlS, AltS, CtrlAltS;
87 static const Event t, T, CtrlT, AltT, CtrlAltT;
88 static const Event u, U, CtrlU, AltU, CtrlAltU;
89 static const Event v, V, CtrlV, AltV, CtrlAltV;
90 static const Event w, W, CtrlW, AltW, CtrlAltW;
91 static const Event x, X, CtrlX, AltX, CtrlAltX;
92 static const Event y, Y, CtrlY, AltY, CtrlAltY;
93 static const Event z, Z, CtrlZ, AltZ, CtrlAltZ;
94
95 // --- 自定义 ---
96 static const Event Custom;
97
98 //--- 方法部分 -------------------------------------------------------------
99 bool operator==(const Event& other) const { return input_ == other.input_; }
100 bool operator!=(const Event& other) const { return !operator==(other); }
101 bool operator<(const Event& other) const { return input_ < other.input_; }
102
103 const std::string& input() const { return input_; }
104
105 bool is_character() const { return type_ == Type::Character; }
106 std::string character() const { return input_; }
107
108 bool is_mouse() const { return type_ == Type::Mouse; }
109 struct Mouse& mouse() { return data_.mouse; }
110
111 // --- 内部方法部分 ----------------------------------------------------------
112 bool is_cursor_position() const { return type_ == Type::CursorPosition; }
113 int cursor_x() const { return data_.cursor.x; }
114 int cursor_y() const { return data_.cursor.y; }
115
116 bool is_cursor_shape() const { return type_ == Type::CursorShape; }
117 int cursor_shape() const { return data_.cursor_shape; }
118
119 // Debug
120 std::string DebugString() const;
121
122 //--- 状态部分 -------------------------------------------------------------
124
125 private:
126 friend ComponentBase;
127 friend ScreenInteractive;
128 enum class Type {
129 Unknown,
130 Character,
131 Mouse,
132 CursorPosition,
133 CursorShape,
134 };
135 Type type_ = Type::Unknown;
136
137 struct Cursor {
138 int x = 0;
139 int y = 0;
140 };
141
142 union {
143 struct Mouse mouse;
144 struct Cursor cursor;
146 } data_ = {};
147
148 std::string input_;
149};
150
151} // namespace ftxui
152
153#endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */
static const Event TabReverse
int cursor_shape() const
static const Event j
static const Event CtrlC
static const Event CtrlP
static const Event CtrlV
static const Event ArrowLeftCtrl
static const Event CtrlL
static const Event AltT
std::string character() const
static const Event w
static const Event CtrlAltX
static const Event D
static const Event CtrlAltN
static const Event a
static Event CursorShape(std::string, int shape)
对应于终端 DCS(设备控制字符串)的事件。
static const Event AltH
static const Event AltF
static const Event K
int cursor_y() const
static const Event T
static const Event CtrlAltC
static const Event X
int cursor_x() const
static const Event CtrlE
static const Event Q
static const Event u
static const Event PageUp
static const Event h
static const Event CtrlAltF
static const Event CtrlZ
static const Event J
static const Event CtrlU
static const Event AltQ
static const Event b
static const Event Escape
static const Event AltY
static const Event CtrlAltI
bool is_mouse() const
static const Event AltL
static const Event AltW
static const Event F12
struct Mouse & mouse()
static const Event E
static const Event m
static const Event N
bool is_cursor_position() const
static const Event CtrlAltP
static const Event CtrlAltE
static const Event F5
static const Event CtrlF
static const Event F3
static const Event CtrlAltJ
static const Event z
static const Event AltK
static const Event B
static const Event H
static const Event CtrlX
static const Event F9
static const Event AltC
static const Event CtrlB
static const Event CtrlAltH
static const Event O
ScreenInteractive * screen_
static const Event R
static const Event AltM
static const Event CtrlR
static const Event CtrlAltW
static const Event CtrlAltO
static const Event CtrlY
static const Event Custom
static const Event A
static const Event AltG
static const Event p
static const Event l
static const Event CtrlH
bool operator<(const Event &other) const
struct Mouse mouse
std::string DebugString() const
返回事件的字符串表示。
static Event Character(std::string)
对应于给定输入字符的事件。
static const Event AltO
static const Event CtrlJ
static const Event CtrlAltM
static const Event CtrlS
static const Event Z
static const Event AltR
static const Event CtrlW
static const Event CtrlN
static const Event F2
static const Event CtrlM
static const Event G
static const Event Backspace
static const Event d
static const Event CtrlAltR
static const Event CtrlK
static const Event x
static const Event F7
static const Event ArrowUp
const std::string & input() const
static const Event Tab
static const Event r
static const Event AltU
static const Event CtrlQ
static const Event CtrlAltZ
static const Event AltN
static const Event AltA
static const Event ArrowDown
struct Cursor cursor
static const Event End
static const Event F11
static const Event CtrlG
static const Event n
static const Event q
static const Event AltZ
static const Event Home
static const Event C
static const Event AltD
static const Event CtrlAltY
static const Event AltJ
static const Event F8
static const Event CtrlAltL
static const Event U
static const Event o
static const Event AltB
static const Event F4
static const Event t
static const Event y
static const Event ArrowUpCtrl
static const Event k
static const Event CtrlAltS
static const Event s
static const Event I
static const Event CtrlT
static const Event F
static const Event AltI
static const Event F10
static const Event AltP
static const Event PageDown
static const Event Y
static const Event CtrlAltK
static Event CursorPosition(std::string, int x, int y)
static const Event F6
static const Event CtrlAltG
static const Event CtrlA
static const Event i
static const Event AltS
static const Event g
static const Event F1
static const Event S
static const Event Return
static const Event CtrlAltU
bool operator==(const Event &other) const
static const Event V
static const Event CtrlAltT
static const Event CtrlAltA
static const Event AltE
static const Event P
static const Event CtrlD
static const Event ArrowLeft
static const Event CtrlAltB
bool operator!=(const Event &other) const
static const Event AltV
static const Event v
static const Event e
bool is_character() const
static const Event CtrlO
static const Event Delete
static const Event CtrlAltV
static const Event ArrowDownCtrl
static const Event AltX
static const Event CtrlAltD
static const Event L
static const Event W
static const Event f
static const Event Insert
static const Event CtrlI
static const Event ArrowRightCtrl
bool is_cursor_shape() const
static const Event c
static const Event CtrlAltQ
static const Event M
static Event Special(std::string)
一个自定义事件,其含义由库用户定义。
static const Event ArrowRight
它将自身实现为 ftxui::Element。它通过响应 ftxui::Event 来实现键盘导航。
ScreenInteractive 是一个可以处理事件、运行主循环和管理组件的 Screen。
代表一个事件。它可以是按键事件、终端大小调整等等...
一个鼠标事件。它包含鼠标的坐标、按下的按钮以及修饰符(shift、ctrl、meta)。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase