FTXUI  3.0.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 // --- Other ---
42 static const Event Backspace;
43 static const Event Delete;
44 static const Event Return;
45 static const Event Escape;
46 static const Event Tab;
47 static const Event TabReverse;
48 static const Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
49
50 static const Event Home;
51 static const Event End;
52
53 static const Event PageUp;
54 static const Event PageDown;
55
56 // --- Custom ---
57 static const Event Custom;
58
59 //--- Method section ---------------------------------------------------------
60 bool is_character() const { return type_ == Type::Character; }
61 std::string character() const { return input_; }
62
63 bool is_mouse() const { return type_ == Type::Mouse; }
64 struct Mouse& mouse() {
65 return mouse_;
66 }
67
68 bool is_cursor_reporting() const { return type_ == Type::CursorReporting; }
69 int cursor_x() const { return cursor_.x; }
70 int cursor_y() const { return cursor_.y; }
71
72 const std::string& input() const { return input_; }
73
74 bool operator==(const Event& other) const { return input_ == other.input_; }
75 bool operator!=(const Event& other) const { return !operator==(other); }
76
77 //--- State section ----------------------------------------------------------
79
80 private:
81 friend ComponentBase;
82 friend ScreenInteractive;
83 enum class Type {
84 Unknown,
85 Character,
86 Mouse,
87 CursorReporting,
88 };
89 Type type_ = Type::Unknown;
90
91 struct Cursor {
92 int x;
93 int y;
94 };
95
96 union {
97 struct Mouse mouse_;
98 struct Cursor cursor_;
99 };
100 std::string input_;
101};
102
103} // namespace ftxui
104
105#endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */
106
107// Copyright 2020 Arthur Sonzogni. All rights reserved.
108// Use of this source code is governed by the MIT license that can be found in
109// 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:47
std::string character() const
Definition event.hpp:61
static Event CursorReporting(std::string, int x, int y)
Definition event.cpp:44
int cursor_y() const
Definition event.hpp:70
int cursor_x() const
Definition event.hpp:69
static const Event PageUp
Definition event.hpp:53
static const Event Escape
Definition event.hpp:45
bool is_mouse() const
Definition event.hpp:63
static const Event F12
Definition event.hpp:48
struct Mouse & mouse()
Definition event.hpp:64
static const Event F5
Definition event.hpp:48
static const Event F3
Definition event.hpp:48
static const Event F9
Definition event.hpp:48
ScreenInteractive * screen_
Definition event.hpp:78
static const Event Custom
Definition event.hpp:57
static Event Character(std::string)
Definition event.cpp:10
static const Event F2
Definition event.hpp:48
static const Event Backspace
Definition event.hpp:42
static const Event F7
Definition event.hpp:48
static const Event ArrowUp
Definition event.hpp:38
const std::string & input() const
Definition event.hpp:72
static const Event Tab
Definition event.hpp:46
static const Event ArrowDown
Definition event.hpp:39
static const Event End
Definition event.hpp:51
static const Event F11
Definition event.hpp:48
static const Event Home
Definition event.hpp:50
static const Event F8
Definition event.hpp:48
static const Event F4
Definition event.hpp:48
static const Event F10
Definition event.hpp:48
static const Event PageDown
Definition event.hpp:54
static const Event F6
Definition event.hpp:48
static const Event F1
Definition event.hpp:48
static const Event Return
Definition event.hpp:44
bool operator==(const Event &other) const
Definition event.hpp:74
static const Event ArrowLeft
Definition event.hpp:36
bool operator!=(const Event &other) const
Definition event.hpp:75
bool is_character() const
Definition event.hpp:60
static const Event Delete
Definition event.hpp:43
bool is_cursor_reporting() const
Definition event.hpp:68
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