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