FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
event.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_EVENT_HPP
5#define FTXUI_COMPONENT_EVENT_HPP
6
7#include <ftxui/component/mouse.hpp> // for Mouse
8#include <string> // for string, operator==
9
10 namespace ftxui {
11
12 class ScreenInteractive;
13 class ComponentBase;
14
15/// @brief Represent an event. It can be key press event, a terminal resize, or
16/// more ...
17///
18/// For example:
19/// - Printable character can be created using Event::Character('a').
20/// - Some special are predefined, like Event::ArrowLeft.
21/// - One can find arbitrary code for special Events using:
22/// ./example/util/print_key_press
23/// For instance, CTLR+A maps to Event::Special({1});
24///
25/// Useful documentation about xterm specification:
26/// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
27///
28/// @ingroup component
29 struct Event {
30 // --- Constructor section ---------------------------------------------------
31 static Event Character(std::string);
32 static Event Character(char);
33 static Event Character(wchar_t);
34 static Event Special(std::string);
35 static Event Mouse(std::string, Mouse mouse);
36 static Event CursorPosition(std::string, int x, int y); // Internal
37 static Event CursorShape(std::string, int shape); // Internal
38
39 // --- Arrow ---
40 static const Event ArrowLeft;
41 static const Event ArrowRight;
42 static const Event ArrowUp;
43 static const Event ArrowDown;
44
45 static const Event ArrowLeftCtrl;
46 static const Event ArrowRightCtrl;
47 static const Event ArrowUpCtrl;
48 static const Event ArrowDownCtrl;
49
50 // --- Other ---
51 static const Event Backspace;
52 static const Event Delete;
53 static const Event Return;
54 static const Event Escape;
55 static const Event Tab;
56 static const Event TabReverse;
57
58 // --- Navigation keys ---
59 static const Event Insert;
60 static const Event Home;
61 static const Event End;
62 static const Event PageUp;
63 static const Event PageDown;
64
65 // --- Function keys ---
66 static const Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
67
68 // --- Control keys ---
69 static const Event a, A, CtrlA, AltA, CtrlAltA;
70 static const Event b, B, CtrlB, AltB, CtrlAltB;
71 static const Event c, C, CtrlC, AltC, CtrlAltC;
72 static const Event d, D, CtrlD, AltD, CtrlAltD;
73 static const Event e, E, CtrlE, AltE, CtrlAltE;
74 static const Event f, F, CtrlF, AltF, CtrlAltF;
75 static const Event g, G, CtrlG, AltG, CtrlAltG;
76 static const Event h, H, CtrlH, AltH, CtrlAltH;
77 static const Event i, I, CtrlI, AltI, CtrlAltI;
78 static const Event j, J, CtrlJ, AltJ, CtrlAltJ;
79 static const Event k, K, CtrlK, AltK, CtrlAltK;
80 static const Event l, L, CtrlL, AltL, CtrlAltL;
81 static const Event m, M, CtrlM, AltM, CtrlAltM;
82 static const Event n, N, CtrlN, AltN, CtrlAltN;
83 static const Event o, O, CtrlO, AltO, CtrlAltO;
84 static const Event p, P, CtrlP, AltP, CtrlAltP;
85 static const Event q, Q, CtrlQ, AltQ, CtrlAltQ;
86 static const Event r, R, CtrlR, AltR, CtrlAltR;
87 static const Event s, S, CtrlS, AltS, CtrlAltS;
88 static const Event t, T, CtrlT, AltT, CtrlAltT;
89 static const Event u, U, CtrlU, AltU, CtrlAltU;
90 static const Event v, V, CtrlV, AltV, CtrlAltV;
91 static const Event w, W, CtrlW, AltW, CtrlAltW;
92 static const Event x, X, CtrlX, AltX, CtrlAltX;
93 static const Event y, Y, CtrlY, AltY, CtrlAltY;
94 static const Event z, Z, CtrlZ, AltZ, CtrlAltZ;
95
96 // --- Custom ---
97 static const Event Custom;
98
99 //--- Method section ---------------------------------------------------------
100 bool operator==(const Event& other) const { return input_ == other.input_; }
101 bool operator!=(const Event& other) const { return !operator==(other); }
102 bool operator<(const Event& other) const { return input_ < other.input_; }
103
104 const std::string& input() const { return input_; }
105
106 bool is_character() const { return type_ == Type::Character; }
107 std::string character() const { return input_; }
108
109 bool is_mouse() const { return type_ == Type::Mouse; }
110 struct Mouse& mouse() { return data_.mouse; }
111
112 // --- Internal Method section -----------------------------------------------
113 bool is_cursor_position() const { return type_ == Type::CursorPosition; }
114 int cursor_x() const { return data_.cursor.x; }
115 int cursor_y() const { return data_.cursor.y; }
116
117 bool is_cursor_shape() const { return type_ == Type::CursorShape; }
118 int cursor_shape() const { return data_.cursor_shape; }
119
120 // Debug
121 std::string DebugString() const;
122
123 //--- State section ----------------------------------------------------------
124 ScreenInteractive* screen_ = nullptr;
125
126 private:
127 friend ComponentBase;
128 friend ScreenInteractive;
129 enum class Type {
130 Unknown,
131 Character,
132 Mouse,
133 CursorPosition,
134 CursorShape,
135 };
136 Type type_ = Type::Unknown;
137
138 struct Cursor {
139 int x = 0;
140 int y = 0;
141 };
142
143 union {
144 struct Mouse mouse;
145 struct Cursor cursor;
146 int cursor_shape;
147 } data_ = {};
148
149 std::string input_;
150};
151
152} // namespace ftxui
153
154#endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */
ftxui::Event::TabReverse
static const Event TabReverse
Definition event.hpp:56
ftxui::Event::cursor_shape
int cursor_shape() const
Definition event.hpp:118
ftxui::Event::j
static const Event j
Definition event.hpp:78
ftxui::Event::CtrlC
static const Event CtrlC
Definition event.hpp:71
ftxui::Event::CtrlP
static const Event CtrlP
Definition event.hpp:84
ftxui::Event::CtrlV
static const Event CtrlV
Definition event.hpp:90
ftxui::Event::ArrowLeftCtrl
static const Event ArrowLeftCtrl
Definition event.hpp:45
ftxui::Event::CtrlL
static const Event CtrlL
Definition event.hpp:80
ftxui::Event::AltT
static const Event AltT
Definition event.hpp:88
ftxui::Event::character
std::string character() const
Definition event.hpp:107
ftxui::Event::w
static const Event w
Definition event.hpp:91
ftxui::Event::CtrlAltX
static const Event CtrlAltX
Definition event.hpp:92
ftxui::Event::D
static const Event D
Definition event.hpp:72
ftxui::Event::CtrlAltN
static const Event CtrlAltN
Definition event.hpp:82
ftxui::Event::a
static const Event a
Definition event.hpp:69
ftxui::Event::CursorShape
static Event CursorShape(std::string, int shape)
An event corresponding to a terminal DCS (Device Control String).
Definition event.cpp:63
ftxui::Event::AltH
static const Event AltH
Definition event.hpp:76
ftxui::Event::AltF
static const Event AltF
Definition event.hpp:74
ftxui::Event::K
static const Event K
Definition event.hpp:79
ftxui::Event::cursor_y
int cursor_y() const
Definition event.hpp:115
ftxui::Event::T
static const Event T
Definition event.hpp:88
ftxui::Event::CtrlAltC
static const Event CtrlAltC
Definition event.hpp:71
ftxui::Event::X
static const Event X
Definition event.hpp:92
ftxui::Event::cursor_x
int cursor_x() const
Definition event.hpp:114
ftxui::Event::CtrlE
static const Event CtrlE
Definition event.hpp:73
ftxui::Event::Q
static const Event Q
Definition event.hpp:85
ftxui::Event::u
static const Event u
Definition event.hpp:89
ftxui::Event::PageUp
static const Event PageUp
Definition event.hpp:62
ftxui::Event::h
static const Event h
Definition event.hpp:76
ftxui::Event::CtrlAltF
static const Event CtrlAltF
Definition event.hpp:74
ftxui::Event::CtrlZ
static const Event CtrlZ
Definition event.hpp:94
ftxui::Event::J
static const Event J
Definition event.hpp:78
ftxui::Event::cursor_shape
int cursor_shape
Definition event.hpp:146
ftxui::Event::CtrlU
static const Event CtrlU
Definition event.hpp:89
ftxui::Event::AltQ
static const Event AltQ
Definition event.hpp:85
ftxui::Event::b
static const Event b
Definition event.hpp:70
ftxui::Event::Escape
static const Event Escape
Definition event.hpp:54
ftxui::Event::AltY
static const Event AltY
Definition event.hpp:93
ftxui::Event::CtrlAltI
static const Event CtrlAltI
Definition event.hpp:77
ftxui::Event::is_mouse
bool is_mouse() const
Definition event.hpp:109
ftxui::Event::AltL
static const Event AltL
Definition event.hpp:80
ftxui::Event::AltW
static const Event AltW
Definition event.hpp:91
ftxui::Event::F12
static const Event F12
Definition event.hpp:66
ftxui::Event::mouse
struct Mouse & mouse()
Definition event.hpp:110
ftxui::Event::E
static const Event E
Definition event.hpp:73
ftxui::Event::m
static const Event m
Definition event.hpp:81
ftxui::Event::N
static const Event N
Definition event.hpp:82
ftxui::Event::is_cursor_position
bool is_cursor_position() const
Definition event.hpp:113
ftxui::Event::CtrlAltP
static const Event CtrlAltP
Definition event.hpp:84
ftxui::Event::CtrlAltE
static const Event CtrlAltE
Definition event.hpp:73
ftxui::Event::F5
static const Event F5
Definition event.hpp:66
ftxui::Event::CtrlF
static const Event CtrlF
Definition event.hpp:74
ftxui::Event::F3
static const Event F3
Definition event.hpp:66
ftxui::Event::CtrlAltJ
static const Event CtrlAltJ
Definition event.hpp:78
ftxui::Event::z
static const Event z
Definition event.hpp:94
ftxui::Event::AltK
static const Event AltK
Definition event.hpp:79
ftxui::Event::B
static const Event B
Definition event.hpp:70
ftxui::Event::H
static const Event H
Definition event.hpp:76
ftxui::Event::CtrlX
static const Event CtrlX
Definition event.hpp:92
ftxui::Event::F9
static const Event F9
Definition event.hpp:66
ftxui::Event::AltC
static const Event AltC
Definition event.hpp:71
ftxui::Event::CtrlB
static const Event CtrlB
Definition event.hpp:70
ftxui::Event::CtrlAltH
static const Event CtrlAltH
Definition event.hpp:76
ftxui::Event::O
static const Event O
Definition event.hpp:83
ftxui::Event::screen_
ScreenInteractive * screen_
Definition event.hpp:124
ftxui::Event::R
static const Event R
Definition event.hpp:86
ftxui::Event::AltM
static const Event AltM
Definition event.hpp:81
ftxui::Event::CtrlR
static const Event CtrlR
Definition event.hpp:86
ftxui::Event::CtrlAltW
static const Event CtrlAltW
Definition event.hpp:91
ftxui::Event::CtrlAltO
static const Event CtrlAltO
Definition event.hpp:83
ftxui::Event::CtrlY
static const Event CtrlY
Definition event.hpp:93
ftxui::Event::Custom
static const Event Custom
Definition event.hpp:97
ftxui::Event::A
static const Event A
Definition event.hpp:69
ftxui::Event::AltG
static const Event AltG
Definition event.hpp:75
ftxui::Event::p
static const Event p
Definition event.hpp:84
ftxui::Event::l
static const Event l
Definition event.hpp:80
ftxui::Event::CtrlH
static const Event CtrlH
Definition event.hpp:76
ftxui::Event::operator<
bool operator<(const Event &other) const
Definition event.hpp:102
ftxui::Event::mouse
struct Mouse mouse
Definition event.hpp:144
ftxui::Event::DebugString
std::string DebugString() const
Return a string representation of the event.
Definition event.cpp:91
ftxui::Event::Character
static Event Character(std::string)
An event corresponding to a given typed character.
Definition event.cpp:28
ftxui::Event::AltO
static const Event AltO
Definition event.hpp:83
ftxui::Event::CtrlJ
static const Event CtrlJ
Definition event.hpp:78
ftxui::Event::CtrlAltM
static const Event CtrlAltM
Definition event.hpp:81
ftxui::Event::CtrlS
static const Event CtrlS
Definition event.hpp:87
ftxui::Event::Z
static const Event Z
Definition event.hpp:94
ftxui::Event::AltR
static const Event AltR
Definition event.hpp:86
ftxui::Event::CtrlW
static const Event CtrlW
Definition event.hpp:91
ftxui::Event::CtrlN
static const Event CtrlN
Definition event.hpp:82
ftxui::Event::F2
static const Event F2
Definition event.hpp:66
ftxui::Event::CtrlM
static const Event CtrlM
Definition event.hpp:81
ftxui::Event::G
static const Event G
Definition event.hpp:75
ftxui::Event::Backspace
static const Event Backspace
Definition event.hpp:51
ftxui::Event::d
static const Event d
Definition event.hpp:72
ftxui::Event::CtrlAltR
static const Event CtrlAltR
Definition event.hpp:86
ftxui::Event::CtrlK
static const Event CtrlK
Definition event.hpp:79
ftxui::Event::x
static const Event x
Definition event.hpp:92
ftxui::Event::F7
static const Event F7
Definition event.hpp:66
ftxui::Event::ArrowUp
static const Event ArrowUp
Definition event.hpp:42
ftxui::Event::input
const std::string & input() const
Definition event.hpp:104
ftxui::Event::Tab
static const Event Tab
Definition event.hpp:55
ftxui::Event::r
static const Event r
Definition event.hpp:86
ftxui::Event::AltU
static const Event AltU
Definition event.hpp:89
ftxui::Event::CtrlQ
static const Event CtrlQ
Definition event.hpp:85
ftxui::Event::CtrlAltZ
static const Event CtrlAltZ
Definition event.hpp:94
ftxui::Event::AltN
static const Event AltN
Definition event.hpp:82
ftxui::Event::AltA
static const Event AltA
Definition event.hpp:69
ftxui::Event::ArrowDown
static const Event ArrowDown
Definition event.hpp:43
ftxui::Event::cursor
struct Cursor cursor
Definition event.hpp:145
ftxui::Event::End
static const Event End
Definition event.hpp:61
ftxui::Event::F11
static const Event F11
Definition event.hpp:66
ftxui::Event::CtrlG
static const Event CtrlG
Definition event.hpp:75
ftxui::Event::n
static const Event n
Definition event.hpp:82
ftxui::Event::q
static const Event q
Definition event.hpp:85
ftxui::Event::AltZ
static const Event AltZ
Definition event.hpp:94
ftxui::Event::Home
static const Event Home
Definition event.hpp:60
ftxui::Event::C
static const Event C
Definition event.hpp:71
ftxui::Event::AltD
static const Event AltD
Definition event.hpp:72
ftxui::Event::CtrlAltY
static const Event CtrlAltY
Definition event.hpp:93
ftxui::Event::AltJ
static const Event AltJ
Definition event.hpp:78
ftxui::Event::F8
static const Event F8
Definition event.hpp:66
ftxui::Event::CtrlAltL
static const Event CtrlAltL
Definition event.hpp:80
ftxui::Event::U
static const Event U
Definition event.hpp:89
ftxui::Event::o
static const Event o
Definition event.hpp:83
ftxui::Event::AltB
static const Event AltB
Definition event.hpp:70
ftxui::Event::F4
static const Event F4
Definition event.hpp:66
ftxui::Event::t
static const Event t
Definition event.hpp:88
ftxui::Event::y
static const Event y
Definition event.hpp:93
ftxui::Event::ArrowUpCtrl
static const Event ArrowUpCtrl
Definition event.hpp:47
ftxui::Event::k
static const Event k
Definition event.hpp:79
ftxui::Event::CtrlAltS
static const Event CtrlAltS
Definition event.hpp:87
ftxui::Event::s
static const Event s
Definition event.hpp:87
ftxui::Event::I
static const Event I
Definition event.hpp:77
ftxui::Event::CtrlT
static const Event CtrlT
Definition event.hpp:88
ftxui::Event::F
static const Event F
Definition event.hpp:74
ftxui::Event::AltI
static const Event AltI
Definition event.hpp:77
ftxui::Event::F10
static const Event F10
Definition event.hpp:66
ftxui::Event::AltP
static const Event AltP
Definition event.hpp:84
ftxui::Event::PageDown
static const Event PageDown
Definition event.hpp:63
ftxui::Event::Y
static const Event Y
Definition event.hpp:93
ftxui::Event::CtrlAltK
static const Event CtrlAltK
Definition event.hpp:79
ftxui::Event::CursorPosition
static Event CursorPosition(std::string, int x, int y)
Definition event.cpp:82
ftxui::Event::F6
static const Event F6
Definition event.hpp:66
ftxui::Event::CtrlAltG
static const Event CtrlAltG
Definition event.hpp:75
ftxui::Event::CtrlA
static const Event CtrlA
Definition event.hpp:69
ftxui::Event::i
static const Event i
Definition event.hpp:77
ftxui::Event::AltS
static const Event AltS
Definition event.hpp:87
ftxui::Event::g
static const Event g
Definition event.hpp:75
ftxui::Event::F1
static const Event F1
Definition event.hpp:66
ftxui::Event::S
static const Event S
Definition event.hpp:87
ftxui::Event::Return
static const Event Return
Definition event.hpp:53
ftxui::Event::CtrlAltU
static const Event CtrlAltU
Definition event.hpp:89
ftxui::Event::operator==
bool operator==(const Event &other) const
Definition event.hpp:100
ftxui::Event::V
static const Event V
Definition event.hpp:90
ftxui::Event::CtrlAltT
static const Event CtrlAltT
Definition event.hpp:88
ftxui::Event::CtrlAltA
static const Event CtrlAltA
Definition event.hpp:69
ftxui::Event::AltE
static const Event AltE
Definition event.hpp:73
ftxui::Event::P
static const Event P
Definition event.hpp:84
ftxui::Event::CtrlD
static const Event CtrlD
Definition event.hpp:72
ftxui::Event::ArrowLeft
static const Event ArrowLeft
Definition event.hpp:40
ftxui::Event::CtrlAltB
static const Event CtrlAltB
Definition event.hpp:70
ftxui::Event::operator!=
bool operator!=(const Event &other) const
Definition event.hpp:101
ftxui::Event::AltV
static const Event AltV
Definition event.hpp:90
ftxui::Event::v
static const Event v
Definition event.hpp:90
ftxui::Event::e
static const Event e
Definition event.hpp:73
ftxui::Event::is_character
bool is_character() const
Definition event.hpp:106
ftxui::Event::CtrlO
static const Event CtrlO
Definition event.hpp:83
ftxui::Event::Delete
static const Event Delete
Definition event.hpp:52
ftxui::Event::CtrlAltV
static const Event CtrlAltV
Definition event.hpp:90
ftxui::Event::ArrowDownCtrl
static const Event ArrowDownCtrl
Definition event.hpp:48
ftxui::Event::AltX
static const Event AltX
Definition event.hpp:92
ftxui::Event::CtrlAltD
static const Event CtrlAltD
Definition event.hpp:72
ftxui::Event::L
static const Event L
Definition event.hpp:80
ftxui::Event::W
static const Event W
Definition event.hpp:91
ftxui::Event::f
static const Event f
Definition event.hpp:74
ftxui::Event::Insert
static const Event Insert
Definition event.hpp:59
ftxui::Event::CtrlI
static const Event CtrlI
Definition event.hpp:77
ftxui::Event::ArrowRightCtrl
static const Event ArrowRightCtrl
Definition event.hpp:46
ftxui::Event::is_cursor_shape
bool is_cursor_shape() const
Definition event.hpp:117
ftxui::Event::c
static const Event c
Definition event.hpp:71
ftxui::Event::CtrlAltQ
static const Event CtrlAltQ
Definition event.hpp:85
ftxui::Event::M
static const Event M
Definition event.hpp:81
ftxui::Event::Special
static Event Special(std::string)
An custom event whose meaning is defined by the user of the library.
Definition event.cpp:74
ftxui::Event::ArrowRight
static const Event ArrowRight
Definition event.hpp:41
ftxui::ComponentBase
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
Definition component_base.hpp:30
ftxui::ScreenInteractive
ScreenInteractive is a Screen that can handle events, run a main loop, and manage components.
Definition screen_interactive.hpp:33
ftxui::Event
Represent an event. It can be key press event, a terminal resize, or more ...
Definition event.hpp:29
ftxui::Mouse
A mouse event. It contains the coordinate of the mouse, the button pressed and the modifier (shift,...
Definition mouse.hpp:11
mouse.hpp
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10