FTXUI  4.1.1
C++ functional terminal UI.
Loading...
Searching...
No Matches
event.cpp
Go to the documentation of this file.
1#include <utility> // for move
2
4#include "ftxui/component/mouse.hpp" // for Mouse
5#include "ftxui/screen/string.hpp" // for to_wstring
6
7namespace ftxui {
8
9// static
10Event Event::Character(std::string input) {
11 Event event;
12 event.input_ = std::move(input);
13 event.type_ = Type::Character;
14 return event;
15}
16
17// static
18Event Event::Character(char c) {
19 return Event::Character(std::string{c});
20}
21
22// static
23Event Event::Character(wchar_t c) {
24 return Event::Character(to_string(std::wstring{c}));
25}
26
27// static
28Event Event::Mouse(std::string input, struct Mouse mouse) {
29 Event event;
30 event.input_ = std::move(input);
31 event.type_ = Type::Mouse;
32 event.mouse_ = mouse; // NOLINT
33 return event;
34}
35
36// static
37Event Event::Special(std::string input) {
38 Event event;
39 event.input_ = std::move(input);
40 return event;
41}
42
43// static
44Event Event::CursorReporting(std::string input, int x, int y) {
45 Event event;
46 event.input_ = std::move(input);
47 event.type_ = Type::CursorReporting;
48 event.cursor_.x = x; // NOLINT
49 event.cursor_.y = y; // NOLINT
50 return event;
51}
52
53// --- Arrow ---
54const Event Event::ArrowLeft = Event::Special("\x1B[D"); // NOLINT
55const Event Event::ArrowRight = Event::Special("\x1B[C"); // NOLINT
56const Event Event::ArrowUp = Event::Special("\x1B[A"); // NOLINT
57const Event Event::ArrowDown = Event::Special("\x1B[B"); // NOLINT
58const Event Event::ArrowLeftCtrl = Event::Special("\x1B[1;5D"); // NOLINT
59const Event Event::ArrowRightCtrl = Event::Special("\x1B[1;5C"); // NOLINT
60const Event Event::ArrowUpCtrl = Event::Special("\x1B[1;5A"); // NOLINT
61const Event Event::ArrowDownCtrl = Event::Special("\x1B[1;5B"); // NOLINT
62const Event Event::Backspace = Event::Special({127}); // NOLINT
63const Event Event::Delete = Event::Special("\x1B[3~"); // NOLINT
64const Event Event::Escape = Event::Special("\x1B"); // NOLINT
65const Event Event::Return = Event::Special({10}); // NOLINT
66const Event Event::Tab = Event::Special({9}); // NOLINT
67const Event Event::TabReverse = Event::Special({27, 91, 90}); // NOLINT
68
69// See https://invisible-island.net/xterm/xterm-function-keys.html
70// We follow xterm-new / vterm-xf86-v4 / mgt / screen
71const Event Event::F1 = Event::Special("\x1BOP"); // NOLINT
72const Event Event::F2 = Event::Special("\x1BOQ"); // NOLINT
73const Event Event::F3 = Event::Special("\x1BOR"); // NOLINT
74const Event Event::F4 = Event::Special("\x1BOS"); // NOLINT
75const Event Event::F5 = Event::Special("\x1B[15~"); // NOLINT
76const Event Event::F6 = Event::Special("\x1B[17~"); // NOLINT
77const Event Event::F7 = Event::Special("\x1B[18~"); // NOLINT
78const Event Event::F8 = Event::Special("\x1B[19~"); // NOLINT
79const Event Event::F9 = Event::Special("\x1B[20~"); // NOLINT
80const Event Event::F10 = Event::Special("\x1B[21~"); // NOLINT
81const Event Event::F11 = Event::Special("\x1B[23~"); // NOLINT
82const Event Event::F12 = Event::Special("\x1B[24~"); // NOLINT
83
84const Event Event::Home = Event::Special({27, 91, 72}); // NOLINT
85const Event Event::End = Event::Special({27, 91, 70}); // NOLINT
86const Event Event::PageUp = Event::Special({27, 91, 53, 126}); // NOLINT
87const Event Event::PageDown = Event::Special({27, 91, 54, 126}); // NOLINT
88const Event Event::Custom = Event::Special({0}); // NOLINT
89
90} // namespace ftxui
91
92// Copyright 2020 Arthur Sonzogni. All rights reserved.
93// Use of this source code is governed by the MIT license that can be found in
94// the LICENSE file.
std::string to_string(const std::wstring &s)
Convert a UTF8 std::string into a std::wstring.
Definition string.cpp:1899
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
static const Event PageUp
Definition event.hpp:58
static const Event Escape
Definition event.hpp:50
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
static const Event Custom
Definition event.hpp:62
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
static const Event ArrowLeft
Definition event.hpp:36
static const Event Delete
Definition event.hpp:48
static const Event ArrowDownCtrl
Definition event.hpp:44
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