FTXUI  4.1.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1#ifndef FTXUI_COMPONENT_EVENT_HPP
2#define FTXUI_COMPONENT_EVENT_HPP
3
4#include <ftxui/component/mouse.hpp> // for Mouse
5#include <functional>
6#include <string> // for string, operator==
7#include <vector>
8
9namespace ftxui {
10
11class ScreenInteractive;
12class ComponentBase;
13
14/// @brief Represent an event. It can be key press event, a terminal resize, or
15/// more ...
16///
17/// For example:
18/// - Printable character can be created using Event::Character('a').
19/// - Some special are predefined, like Event::ArrowLeft.
20/// - One can find arbitrary code for special Events using:
21/// ./example/util/print_key_press
22/// For instance, CTLR+A maps to Event::Special({1});
23///
24/// Useful documentation about xterm specification:
25/// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
26struct Event {
27 // --- Constructor section ---------------------------------------------------
28 static Event Character(std::string);
29 static Event Character(char);
30 static Event Character(wchar_t);
31 static Event Special(std::string);
32 static Event Mouse(std::string, Mouse mouse);
33 static Event CursorReporting(std::string, int x, int y);
34
35 // --- Arrow ---
36 static const Event ArrowLeft;
37 static const Event ArrowRight;
38 static const Event ArrowUp;
39 static const Event ArrowDown;
40
41 static const Event ArrowLeftCtrl;
42 static const Event ArrowRightCtrl;
43 static const Event ArrowUpCtrl;
44 static const Event ArrowDownCtrl;
45
46 // --- Other ---
47 static const Event Backspace;
48 static const Event Delete;
49 static const Event Return;
50 static const Event Escape;
51 static const Event Tab;
52 static const Event TabReverse;
53 static const Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
54
55 static const Event Home;
56 static const Event End;
57
58 static const Event PageUp;
59 static const Event PageDown;
60
61 // --- Custom ---
62 static const Event Custom;
63
64 //--- Method section ---------------------------------------------------------
65 bool is_character() const { return type_ == Type::Character; }
66 std::string character() const { return input_; }
67
68 bool is_mouse() const { return type_ == Type::Mouse; }
69 struct Mouse& mouse() { return mouse_; }
70
71 bool is_cursor_reporting() const { return type_ == Type::CursorReporting; }
72 int cursor_x() const { return cursor_.x; }
73 int cursor_y() const { return cursor_.y; }
74
75 const std::string& input() const { return input_; }
76
77 bool operator==(const Event& other) const { return input_ == other.input_; }
78 bool operator!=(const Event& other) const { return !operator==(other); }
79
80 //--- State section ----------------------------------------------------------
82
83 private:
84 friend ComponentBase;
85 friend ScreenInteractive;
86 enum class Type {
87 Unknown,
88 Character,
89 Mouse,
90 CursorReporting,
91 };
92 Type type_ = Type::Unknown;
93
94 struct Cursor {
95 int x;
96 int y;
97 };
98
99 union {
100 struct Mouse mouse_;
101 struct Cursor cursor_;
102 };
103 std::string input_;
104};
105
106} // namespace ftxui
107
108#endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */
109
110// Copyright 2020 Arthur Sonzogni. All rights reserved.
111// Use of this source code is governed by the MIT license that can be found in
112// the LICENSE file.
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
Represent an event. It can be key press event, a terminal resize, or more ...
Definition event.hpp:26
static const Event TabReverse
Definition event.hpp:52
static const Event ArrowLeftCtrl
Definition event.hpp:41
std::string character() const
Definition event.hpp:66
static Event CursorReporting(std::string, int x, int y)
Definition event.cpp:44
int cursor_y() const
Definition event.hpp:73
int cursor_x() const
Definition event.hpp:72
static const Event PageUp
Definition event.hpp:58
static const Event Escape
Definition event.hpp:50
bool is_mouse() const
Definition event.hpp:68
static const Event F12
Definition event.hpp:53
struct Mouse & mouse()
Definition event.hpp:69
static const Event F5
Definition event.hpp:53
static const Event F3
Definition event.hpp:53
static const Event F9
Definition event.hpp:53
ScreenInteractive * screen_
Definition event.hpp:81
static const Event Custom
Definition event.hpp:62
static Event Character(std::string)
Definition event.cpp:10
static const Event F2
Definition event.hpp:53
static const Event Backspace
Definition event.hpp:47
static const Event F7
Definition event.hpp:53
static const Event ArrowUp
Definition event.hpp:38
const std::string & input() const
Definition event.hpp:75
static const Event Tab
Definition event.hpp:51
static const Event ArrowDown
Definition event.hpp:39
static const Event End
Definition event.hpp:56
static const Event F11
Definition event.hpp:53
static const Event Home
Definition event.hpp:55
static const Event F8
Definition event.hpp:53
static const Event F4
Definition event.hpp:53
static const Event ArrowUpCtrl
Definition event.hpp:43
static const Event F10
Definition event.hpp:53
static const Event PageDown
Definition event.hpp:59
static const Event F6
Definition event.hpp:53
static const Event F1
Definition event.hpp:53
static const Event Return
Definition event.hpp:49
bool operator==(const Event &other) const
Definition event.hpp:77
static const Event ArrowLeft
Definition event.hpp:36
bool operator!=(const Event &other) const
Definition event.hpp:78
bool is_character() const
Definition event.hpp:65
static const Event Delete
Definition event.hpp:48
static const Event ArrowDownCtrl
Definition event.hpp:44
bool is_cursor_reporting() const
Definition event.hpp:71
static const Event ArrowRightCtrl
Definition event.hpp:42
static Event Special(std::string)
Definition event.cpp:37
static const Event ArrowRight
Definition event.hpp:37
A mouse event. It contains the coordinate of the mouse, the button pressed and the modifier (shift,...
Definition mouse.hpp:8