Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#ifndef FTXUI_COMPONENT_EVENT_HPP
#define FTXUI_COMPONENT_EVENT_HPP
#include <ftxui/component/mouse.hpp> // for Mouse
#include <string> // for string, operator==
namespace ftxui {
class ScreenInteractive;
class ComponentBase;
/// @brief Represent an event. It can be key press event, a terminal resize, or
/// more ...
///
/// For example:
/// - Printable character can be created using Event::Character('a').
/// - Some special are predefined, like Event::ArrowLeft.
/// - One can find arbitrary code for special Events using:
/// ./example/util/print_key_press
/// For instance, CTLR+A maps to Event::Special({1});
///
/// Useful documentation about xterm specification:
/// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
struct Event {
// --- Constructor section ---------------------------------------------------
static Event Character(std::string);
static Event Character(char);
static Event Character(wchar_t);
static Event Special(std::string);
static Event Mouse(std::string, Mouse mouse);
static Event CursorPosition(std::string, int x, int y); // Internal
static Event CursorShape(std::string, int shape); // Internal
// --- Arrow ---
static const Event ArrowLeft;
static const Event ArrowRight;
static const Event ArrowUp;
static const Event ArrowDown;
static const Event ArrowLeftCtrl;
static const Event ArrowRightCtrl;
static const Event ArrowUpCtrl;
static const Event ArrowDownCtrl;
// --- Other ---
static const Event Backspace;
static const Event Delete;
static const Event Return;
static const Event Escape;
static const Event Tab;
static const Event TabReverse;
// --- Navigation keys ---
static const Event Insert;
static const Event Home;
static const Event End;
static const Event PageUp;
static const Event PageDown;
// --- Function keys ---
static const Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
// --- Control keys ---
static const Event a, A, CtrlA, AltA, CtrlAltA;
static const Event b, B, CtrlB, AltB, CtrlAltB;
static const Event c, C, CtrlC, AltC, CtrlAltC;
static const Event d, D, CtrlD, AltD, CtrlAltD;
static const Event e, E, CtrlE, AltE, CtrlAltE;
static const Event f, F, CtrlF, AltF, CtrlAltF;
static const Event g, G, CtrlG, AltG, CtrlAltG;
static const Event h, H, CtrlH, AltH, CtrlAltH;
static const Event i, I, CtrlI, AltI, CtrlAltI;
static const Event j, J, CtrlJ, AltJ, CtrlAltJ;
static const Event k, K, CtrlK, AltK, CtrlAltK;
static const Event l, L, CtrlL, AltL, CtrlAltL;
static const Event m, M, CtrlM, AltM, CtrlAltM;
static const Event n, N, CtrlN, AltN, CtrlAltN;
static const Event o, O, CtrlO, AltO, CtrlAltO;
static const Event p, P, CtrlP, AltP, CtrlAltP;
static const Event q, Q, CtrlQ, AltQ, CtrlAltQ;
static const Event r, R, CtrlR, AltR, CtrlAltR;
static const Event s, S, CtrlS, AltS, CtrlAltS;
static const Event t, T, CtrlT, AltT, CtrlAltT;
static const Event u, U, CtrlU, AltU, CtrlAltU;
static const Event v, V, CtrlV, AltV, CtrlAltV;
static const Event w, W, CtrlW, AltW, CtrlAltW;
static const Event x, X, CtrlX, AltX, CtrlAltX;
static const Event y, Y, CtrlY, AltY, CtrlAltY;
static const Event z, Z, CtrlZ, AltZ, CtrlAltZ;
// --- Custom ---
static const Event Custom;
//--- Method section ---------------------------------------------------------
bool operator==(const Event& other) const { return input_ == other.input_; }
bool operator!=(const Event& other) const { return !operator==(other); }
bool operator<(const Event& other) const { return input_ < other.input_; }
const std::string& input() const { return input_; }
bool is_character() const { return type_ == Type::Character; }
std::string character() const { return input_; }
bool is_mouse() const { return type_ == Type::Mouse; }
struct Mouse& mouse() { return data_.mouse; }
// --- Internal Method section -----------------------------------------------
bool is_cursor_position() const { return type_ == Type::CursorPosition; }
int cursor_x() const { return data_.cursor.x; }
int cursor_y() const { return data_.cursor.y; }
bool is_cursor_shape() const { return type_ == Type::CursorShape; }
int cursor_shape() const { return data_.cursor_shape; }
// Debug
std::string DebugString() const;
//--- State section ----------------------------------------------------------
ScreenInteractive* screen_ = nullptr;
private:
friend ComponentBase;
friend ScreenInteractive;
enum class Type {
Unknown,
Character,
Mouse,
CursorPosition,
CursorShape,
};
Type type_ = Type::Unknown;
struct Cursor {
int x = 0;
int y = 0;
};
union {
struct Mouse mouse;
struct Cursor cursor;
int cursor_shape;
} data_ = {};
std::string input_;
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_EVENT_HPP */
ftxui::ComponentBase
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
Definition component_base.hpp:30
ftxui::ScreenInteractive
Definition screen_interactive.hpp:30
mouse.hpp
ftxui
Definition animation.hpp:10
ftxui::Make
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
ftxui::Event
Represent an event. It can be key press event, a terminal resize, or more ...
Definition event.hpp:27
ftxui::Event::TabReverse
static const Event TabReverse
Definition event.hpp:54
ftxui::Event::cursor_shape
int cursor_shape() const
Definition event.hpp:116
ftxui::Event::j
static const Event j
Definition event.hpp:76
ftxui::Event::CtrlC
static const Event CtrlC
Definition event.hpp:69
ftxui::Event::CtrlP
static const Event CtrlP
Definition event.hpp:82
ftxui::Event::CtrlV
static const Event CtrlV
Definition event.hpp:88
ftxui::Event::ArrowLeftCtrl
static const Event ArrowLeftCtrl
Definition event.hpp:43
ftxui::Event::CtrlL
static const Event CtrlL
Definition event.hpp:78
ftxui::Event::AltT
static const Event AltT
Definition event.hpp:86
ftxui::Event::character
std::string character() const
Definition event.hpp:105
ftxui::Event::w
static const Event w
Definition event.hpp:89
ftxui::Event::CtrlAltX
static const Event CtrlAltX
Definition event.hpp:90
ftxui::Event::D
static const Event D
Definition event.hpp:70
ftxui::Event::CtrlAltN
static const Event CtrlAltN
Definition event.hpp:80
ftxui::Event::a
static const Event a
Definition event.hpp:67
ftxui::Event::CursorShape
static Event CursorShape(std::string, int shape)
An event corresponding to a terminal DCS (Device Control String).
Definition event.cpp:67
ftxui::Event::AltH
static const Event AltH
Definition event.hpp:74
ftxui::Event::AltF
static const Event AltF
Definition event.hpp:72
ftxui::Event::K
static const Event K
Definition event.hpp:77
ftxui::Event::cursor_y
int cursor_y() const
Definition event.hpp:113
ftxui::Event::T
static const Event T
Definition event.hpp:86
ftxui::Event::CtrlAltC
static const Event CtrlAltC
Definition event.hpp:69
ftxui::Event::X
static const Event X
Definition event.hpp:90
ftxui::Event::cursor_x
int cursor_x() const
Definition event.hpp:112
ftxui::Event::CtrlE
static const Event CtrlE
Definition event.hpp:71
ftxui::Event::Q
static const Event Q
Definition event.hpp:83
ftxui::Event::u
static const Event u
Definition event.hpp:87
ftxui::Event::PageUp
static const Event PageUp
Definition event.hpp:60
ftxui::Event::h
static const Event h
Definition event.hpp:74
ftxui::Event::CtrlAltF
static const Event CtrlAltF
Definition event.hpp:72
ftxui::Event::CtrlZ
static const Event CtrlZ
Definition event.hpp:92
ftxui::Event::J
static const Event J
Definition event.hpp:76
ftxui::Event::CtrlU
static const Event CtrlU
Definition event.hpp:87
ftxui::Event::AltQ
static const Event AltQ
Definition event.hpp:83
ftxui::Event::b
static const Event b
Definition event.hpp:68
ftxui::Event::Escape
static const Event Escape
Definition event.hpp:52
ftxui::Event::AltY
static const Event AltY
Definition event.hpp:91
ftxui::Event::CtrlAltI
static const Event CtrlAltI
Definition event.hpp:75
ftxui::Event::is_mouse
bool is_mouse() const
Definition event.hpp:107
ftxui::Event::AltL
static const Event AltL
Definition event.hpp:78
ftxui::Event::AltW
static const Event AltW
Definition event.hpp:89
ftxui::Event::F12
static const Event F12
Definition event.hpp:64
ftxui::Event::mouse
struct Mouse & mouse()
Definition event.hpp:108
ftxui::Event::E
static const Event E
Definition event.hpp:71
ftxui::Event::m
static const Event m
Definition event.hpp:79
ftxui::Event::N
static const Event N
Definition event.hpp:80
ftxui::Event::is_cursor_position
bool is_cursor_position() const
Definition event.hpp:111
ftxui::Event::CtrlAltP
static const Event CtrlAltP
Definition event.hpp:82
ftxui::Event::CtrlAltE
static const Event CtrlAltE
Definition event.hpp:71
ftxui::Event::F5
static const Event F5
Definition event.hpp:64
ftxui::Event::CtrlF
static const Event CtrlF
Definition event.hpp:72
ftxui::Event::F3
static const Event F3
Definition event.hpp:64
ftxui::Event::CtrlAltJ
static const Event CtrlAltJ
Definition event.hpp:76
ftxui::Event::z
static const Event z
Definition event.hpp:92
ftxui::Event::AltK
static const Event AltK
Definition event.hpp:77
ftxui::Event::B
static const Event B
Definition event.hpp:68
ftxui::Event::H
static const Event H
Definition event.hpp:74
ftxui::Event::CtrlX
static const Event CtrlX
Definition event.hpp:90
ftxui::Event::F9
static const Event F9
Definition event.hpp:64
ftxui::Event::AltC
static const Event AltC
Definition event.hpp:69
ftxui::Event::CtrlB
static const Event CtrlB
Definition event.hpp:68
ftxui::Event::CtrlAltH
static const Event CtrlAltH
Definition event.hpp:74
ftxui::Event::O
static const Event O
Definition event.hpp:81
ftxui::Event::screen_
ScreenInteractive * screen_
Definition event.hpp:122
ftxui::Event::R
static const Event R
Definition event.hpp:84
ftxui::Event::AltM
static const Event AltM
Definition event.hpp:79
ftxui::Event::CtrlR
static const Event CtrlR
Definition event.hpp:84
ftxui::Event::CtrlAltW
static const Event CtrlAltW
Definition event.hpp:89
ftxui::Event::CtrlAltO
static const Event CtrlAltO
Definition event.hpp:81
ftxui::Event::CtrlY
static const Event CtrlY
Definition event.hpp:91
ftxui::Event::Custom
static const Event Custom
Definition event.hpp:95
ftxui::Event::A
static const Event A
Definition event.hpp:67
ftxui::Event::AltG
static const Event AltG
Definition event.hpp:73
ftxui::Event::p
static const Event p
Definition event.hpp:82
ftxui::Event::l
static const Event l
Definition event.hpp:78
ftxui::Event::CtrlH
static const Event CtrlH
Definition event.hpp:74
ftxui::Event::operator<
bool operator<(const Event &other) const
Definition event.hpp:100
ftxui::Event::DebugString
std::string DebugString() const
Return a string representation of the event.
Definition event.cpp:96
ftxui::Event::Character
static Event Character(std::string)
An event corresponding to a given typed character.
Definition event.cpp:29
ftxui::Event::AltO
static const Event AltO
Definition event.hpp:81
ftxui::Event::CtrlJ
static const Event CtrlJ
Definition event.hpp:76
ftxui::Event::CtrlAltM
static const Event CtrlAltM
Definition event.hpp:79
ftxui::Event::CtrlS
static const Event CtrlS
Definition event.hpp:85
ftxui::Event::Z
static const Event Z
Definition event.hpp:92
ftxui::Event::AltR
static const Event AltR
Definition event.hpp:84
ftxui::Event::CtrlW
static const Event CtrlW
Definition event.hpp:89
ftxui::Event::CtrlN
static const Event CtrlN
Definition event.hpp:80
ftxui::Event::F2
static const Event F2
Definition event.hpp:64
ftxui::Event::CtrlM
static const Event CtrlM
Definition event.hpp:79
ftxui::Event::G
static const Event G
Definition event.hpp:73
ftxui::Event::Backspace
static const Event Backspace
Definition event.hpp:49
ftxui::Event::d
static const Event d
Definition event.hpp:70
ftxui::Event::CtrlAltR
static const Event CtrlAltR
Definition event.hpp:84
ftxui::Event::CtrlK
static const Event CtrlK
Definition event.hpp:77
ftxui::Event::x
static const Event x
Definition event.hpp:90
ftxui::Event::F7
static const Event F7
Definition event.hpp:64
ftxui::Event::ArrowUp
static const Event ArrowUp
Definition event.hpp:40
ftxui::Event::input
const std::string & input() const
Definition event.hpp:102
ftxui::Event::Tab
static const Event Tab
Definition event.hpp:53
ftxui::Event::r
static const Event r
Definition event.hpp:84
ftxui::Event::AltU
static const Event AltU
Definition event.hpp:87
ftxui::Event::CtrlQ
static const Event CtrlQ
Definition event.hpp:83
ftxui::Event::CtrlAltZ
static const Event CtrlAltZ
Definition event.hpp:92
ftxui::Event::AltN
static const Event AltN
Definition event.hpp:80
ftxui::Event::AltA
static const Event AltA
Definition event.hpp:67
ftxui::Event::ArrowDown
static const Event ArrowDown
Definition event.hpp:41
ftxui::Event::End
static const Event End
Definition event.hpp:59
ftxui::Event::F11
static const Event F11
Definition event.hpp:64
ftxui::Event::CtrlG
static const Event CtrlG
Definition event.hpp:73
ftxui::Event::n
static const Event n
Definition event.hpp:80
ftxui::Event::q
static const Event q
Definition event.hpp:83
ftxui::Event::AltZ
static const Event AltZ
Definition event.hpp:92
ftxui::Event::Home
static const Event Home
Definition event.hpp:58
ftxui::Event::C
static const Event C
Definition event.hpp:69
ftxui::Event::AltD
static const Event AltD
Definition event.hpp:70
ftxui::Event::CtrlAltY
static const Event CtrlAltY
Definition event.hpp:91
ftxui::Event::AltJ
static const Event AltJ
Definition event.hpp:76
ftxui::Event::F8
static const Event F8
Definition event.hpp:64
ftxui::Event::CtrlAltL
static const Event CtrlAltL
Definition event.hpp:78
ftxui::Event::U
static const Event U
Definition event.hpp:87
ftxui::Event::o
static const Event o
Definition event.hpp:81
ftxui::Event::AltB
static const Event AltB
Definition event.hpp:68
ftxui::Event::F4
static const Event F4
Definition event.hpp:64
ftxui::Event::t
static const Event t
Definition event.hpp:86
ftxui::Event::y
static const Event y
Definition event.hpp:91
ftxui::Event::ArrowUpCtrl
static const Event ArrowUpCtrl
Definition event.hpp:45
ftxui::Event::k
static const Event k
Definition event.hpp:77
ftxui::Event::CtrlAltS
static const Event CtrlAltS
Definition event.hpp:85
ftxui::Event::s
static const Event s
Definition event.hpp:85
ftxui::Event::I
static const Event I
Definition event.hpp:75
ftxui::Event::CtrlT
static const Event CtrlT
Definition event.hpp:86
ftxui::Event::F
static const Event F
Definition event.hpp:72
ftxui::Event::AltI
static const Event AltI
Definition event.hpp:75
ftxui::Event::F10
static const Event F10
Definition event.hpp:64
ftxui::Event::AltP
static const Event AltP
Definition event.hpp:82
ftxui::Event::PageDown
static const Event PageDown
Definition event.hpp:61
ftxui::Event::Y
static const Event Y
Definition event.hpp:91
ftxui::Event::CtrlAltK
static const Event CtrlAltK
Definition event.hpp:77
ftxui::Event::CursorPosition
static Event CursorPosition(std::string, int x, int y)
Definition event.cpp:87
ftxui::Event::F6
static const Event F6
Definition event.hpp:64
ftxui::Event::CtrlAltG
static const Event CtrlAltG
Definition event.hpp:73
ftxui::Event::CtrlA
static const Event CtrlA
Definition event.hpp:67
ftxui::Event::i
static const Event i
Definition event.hpp:75
ftxui::Event::AltS
static const Event AltS
Definition event.hpp:85
ftxui::Event::g
static const Event g
Definition event.hpp:73
ftxui::Event::F1
static const Event F1
Definition event.hpp:64
ftxui::Event::S
static const Event S
Definition event.hpp:85
ftxui::Event::Return
static const Event Return
Definition event.hpp:51
ftxui::Event::CtrlAltU
static const Event CtrlAltU
Definition event.hpp:87
ftxui::Event::operator==
bool operator==(const Event &other) const
Definition event.hpp:98
ftxui::Event::V
static const Event V
Definition event.hpp:88
ftxui::Event::CtrlAltT
static const Event CtrlAltT
Definition event.hpp:86
ftxui::Event::CtrlAltA
static const Event CtrlAltA
Definition event.hpp:67
ftxui::Event::AltE
static const Event AltE
Definition event.hpp:71
ftxui::Event::P
static const Event P
Definition event.hpp:82
ftxui::Event::CtrlD
static const Event CtrlD
Definition event.hpp:70
ftxui::Event::ArrowLeft
static const Event ArrowLeft
Definition event.hpp:38
ftxui::Event::CtrlAltB
static const Event CtrlAltB
Definition event.hpp:68
ftxui::Event::operator!=
bool operator!=(const Event &other) const
Definition event.hpp:99
ftxui::Event::AltV
static const Event AltV
Definition event.hpp:88
ftxui::Event::v
static const Event v
Definition event.hpp:88
ftxui::Event::e
static const Event e
Definition event.hpp:71
ftxui::Event::is_character
bool is_character() const
Definition event.hpp:104
ftxui::Event::CtrlO
static const Event CtrlO
Definition event.hpp:81
ftxui::Event::Delete
static const Event Delete
Definition event.hpp:50
ftxui::Event::CtrlAltV
static const Event CtrlAltV
Definition event.hpp:88
ftxui::Event::ArrowDownCtrl
static const Event ArrowDownCtrl
Definition event.hpp:46
ftxui::Event::AltX
static const Event AltX
Definition event.hpp:90
ftxui::Event::CtrlAltD
static const Event CtrlAltD
Definition event.hpp:70
ftxui::Event::L
static const Event L
Definition event.hpp:78
ftxui::Event::W
static const Event W
Definition event.hpp:89
ftxui::Event::f
static const Event f
Definition event.hpp:72
ftxui::Event::Insert
static const Event Insert
Definition event.hpp:57
ftxui::Event::CtrlI
static const Event CtrlI
Definition event.hpp:75
ftxui::Event::ArrowRightCtrl
static const Event ArrowRightCtrl
Definition event.hpp:44
ftxui::Event::is_cursor_shape
bool is_cursor_shape() const
Definition event.hpp:115
ftxui::Event::c
static const Event c
Definition event.hpp:69
ftxui::Event::CtrlAltQ
static const Event CtrlAltQ
Definition event.hpp:83
ftxui::Event::M
static const Event M
Definition event.hpp:79
ftxui::Event::Special
static Event Special(std::string)
An custom event whose meaning is defined by the user of the library.
Definition event.cpp:79
ftxui::Event::ArrowRight
static const Event ArrowRight
Definition event.hpp:39
ftxui::Mouse
A mouse event. It contains the coordinate of the mouse, the button pressed and the modifier (shift,...
Definition mouse.hpp:11