FTXUI  5.0.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
event.cpp
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#include <utility> // for move
5
7#include "ftxui/component/mouse.hpp" // for Mouse
8#include "ftxui/screen/string.hpp" // for to_wstring
9
10namespace ftxui {
11
12/// @brief An event corresponding to a given typed character.
13/// @param input The character typed by the user.
14/// @ingroup component
15// static
16Event Event::Character(std::string input) {
18 event.input_ = std::move(input);
19 event.type_ = Type::Character;
20 return event;
21}
22
23/// @brief An event corresponding to a given typed character.
24/// @param c The character typed by the user.
25/// @ingroup component
26// static
27Event Event::Character(char c) {
28 return Event::Character(std::string{c});
29}
30
31/// @brief An event corresponding to a given typed character.
32/// @param c The character typed by the user.
33/// @ingroup component
34// static
35Event Event::Character(wchar_t c) {
36 return Event::Character(to_string(std::wstring{c}));
37}
38
39/// @brief An event corresponding to a given typed character.
40/// @param input The sequence of character send by the terminal.
41/// @param mouse The mouse state.
42/// @ingroup component
43// static
44Event Event::Mouse(std::string input, struct Mouse mouse) {
46 event.input_ = std::move(input);
47 event.type_ = Type::Mouse;
48 event.data_.mouse = mouse; // NOLINT
49 return event;
50}
51
52/// @brief An custom event whose meaning is defined by the user of the library.
53/// @param input An arbitrary sequence of character defined by the developer.
54/// @ingroup component.
55// static
56Event Event::Special(std::string input) {
58 event.input_ = std::move(input);
59 return event;
60}
61
62/// @internal
63// static
64Event Event::CursorReporting(std::string input, int x, int y) {
66 event.input_ = std::move(input);
67 event.type_ = Type::CursorReporting;
68 event.data_.cursor = {x, y}; // NOLINT
69 return event;
70}
71
72// --- Arrow ---
73const Event Event::ArrowLeft = Event::Special("\x1B[D"); // NOLINT
74const Event Event::ArrowRight = Event::Special("\x1B[C"); // NOLINT
75const Event Event::ArrowUp = Event::Special("\x1B[A"); // NOLINT
76const Event Event::ArrowDown = Event::Special("\x1B[B"); // NOLINT
77const Event Event::ArrowLeftCtrl = Event::Special("\x1B[1;5D"); // NOLINT
78const Event Event::ArrowRightCtrl = Event::Special("\x1B[1;5C"); // NOLINT
79const Event Event::ArrowUpCtrl = Event::Special("\x1B[1;5A"); // NOLINT
80const Event Event::ArrowDownCtrl = Event::Special("\x1B[1;5B"); // NOLINT
81const Event Event::Backspace = Event::Special({127}); // NOLINT
82const Event Event::Delete = Event::Special("\x1B[3~"); // NOLINT
83const Event Event::Escape = Event::Special("\x1B"); // NOLINT
84const Event Event::Return = Event::Special({10}); // NOLINT
85const Event Event::Tab = Event::Special({9}); // NOLINT
86const Event Event::TabReverse = Event::Special({27, 91, 90}); // NOLINT
87
88// See https://invisible-island.net/xterm/xterm-function-keys.html
89// We follow xterm-new / vterm-xf86-v4 / mgt / screen
90const Event Event::F1 = Event::Special("\x1BOP"); // NOLINT
91const Event Event::F2 = Event::Special("\x1BOQ"); // NOLINT
92const Event Event::F3 = Event::Special("\x1BOR"); // NOLINT
93const Event Event::F4 = Event::Special("\x1BOS"); // NOLINT
94const Event Event::F5 = Event::Special("\x1B[15~"); // NOLINT
95const Event Event::F6 = Event::Special("\x1B[17~"); // NOLINT
96const Event Event::F7 = Event::Special("\x1B[18~"); // NOLINT
97const Event Event::F8 = Event::Special("\x1B[19~"); // NOLINT
98const Event Event::F9 = Event::Special("\x1B[20~"); // NOLINT
99const Event Event::F10 = Event::Special("\x1B[21~"); // NOLINT
100const Event Event::F11 = Event::Special("\x1B[23~"); // NOLINT
101const Event Event::F12 = Event::Special("\x1B[24~"); // NOLINT
102
103const Event Event::Home = Event::Special({27, 91, 72}); // NOLINT
104const Event Event::End = Event::Special({27, 91, 70}); // NOLINT
105const Event Event::PageUp = Event::Special({27, 91, 53, 126}); // NOLINT
106const Event Event::PageDown = Event::Special({27, 91, 54, 126}); // NOLINT
107const Event Event::Custom = Event::Special({0}); // NOLINT
108
109} // namespace ftxui
std::string to_string(const std::wstring &s)
Convert a UTF8 std::string into a std::wstring.
Definition string.cpp:1565
Component Slider(SliderOption< T > options)
A slider in any direction.
Definition slider.cpp:339
Represent an event. It can be key press event, a terminal resize, or more ...
Definition event.hpp:29
static const Event TabReverse
Definition event.hpp:55
static const Event ArrowLeftCtrl
Definition event.hpp:44
static const Event PageUp
Definition event.hpp:61
static const Event Escape
Definition event.hpp:53
static const Event F12
Definition event.hpp:56
struct Mouse & mouse()
Definition event.hpp:72
static const Event F5
Definition event.hpp:56
static const Event F3
Definition event.hpp:56
static const Event F9
Definition event.hpp:56
static const Event Custom
Definition event.hpp:65
static const Event F2
Definition event.hpp:56
static const Event Backspace
Definition event.hpp:50
static const Event F7
Definition event.hpp:56
static const Event ArrowUp
Definition event.hpp:41
const std::string & input() const
Definition event.hpp:78
static const Event Tab
Definition event.hpp:54
static const Event ArrowDown
Definition event.hpp:42
static const Event End
Definition event.hpp:59
static const Event F11
Definition event.hpp:56
static const Event Home
Definition event.hpp:58
static const Event F8
Definition event.hpp:56
static const Event F4
Definition event.hpp:56
static const Event ArrowUpCtrl
Definition event.hpp:46
static const Event F10
Definition event.hpp:56
static const Event PageDown
Definition event.hpp:62
static const Event F6
Definition event.hpp:56
static const Event F1
Definition event.hpp:56
static const Event Return
Definition event.hpp:52
static const Event ArrowLeft
Definition event.hpp:39
static const Event Delete
Definition event.hpp:51
static const Event ArrowDownCtrl
Definition event.hpp:47
static const Event ArrowRightCtrl
Definition event.hpp:45
static Event Special(std::string)
An custom event whose meaning is defined by the user of the library.
Definition event.cpp:56
static const Event ArrowRight
Definition event.hpp:40
A mouse event. It contains the coordinate of the mouse, the button pressed and the modifier (shift,...
Definition mouse.hpp:11