FTXUI  0.10.0
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;
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;
49 event.cursor_.y = y;
50 return event;
51}
52
53// --- Arrow ---
54const Event Event::ArrowLeft = Event::Special("\x1B[D");
55const Event Event::ArrowRight = Event::Special("\x1B[C");
56const Event Event::ArrowUp = Event::Special("\x1B[A");
57const Event Event::ArrowDown = Event::Special("\x1B[B");
59const Event Event::Delete = Event::Special("\x1B[3~");
60const Event Event::Escape = Event::Special("\x1B");
61#if defined(_WIN32)
62const Event Event::Return = Event::Special({13});
63#else
64const Event Event::Return = Event::Special({10});
65#endif
66const Event Event::Tab = Event::Special({9});
67const Event Event::TabReverse = Event::Special({27, 91, 90});
68const Event Event::F1 = Event::Special("\x1B[OP");
69const Event Event::F2 = Event::Special("\x1B[OQ");
70const Event Event::F3 = Event::Special("\x1B[OR");
71const Event Event::F4 = Event::Special("\x1B[OS");
72const Event Event::F5 = Event::Special("\x1B[15~");
73const Event Event::F6 = Event::Special("\x1B[17~");
74const Event Event::F7 = Event::Special("\x1B[18~");
75const Event Event::F8 = Event::Special("\x1B[19~");
76const Event Event::F9 = Event::Special("\x1B[20~");
77const Event Event::F10 = Event::Special("\x1B[21~");
78const Event Event::F11 = Event::Special("\x1B[21~"); // Doesn't exist
79const Event Event::F12 = Event::Special("\x1B[24~");
80const Event Event::Home = Event::Special({27, 91, 72});
81const Event Event::End = Event::Special({27, 91, 70});
82const Event Event::PageUp = Event::Special({27, 91, 53, 126});
83const Event Event::PageDown = Event::Special({27, 91, 54, 126});
84
85Event Event::Custom = Event::Special({0});
86
87} // namespace ftxui
88
89// Copyright 2020 Arthur Sonzogni. All rights reserved.
90// Use of this source code is governed by the MIT license that can be found in
91// the LICENSE file.
std::string to_string(const std::wstring &s)
Convert a UTF8 std::string into a std::wstring.
Definition string.cpp:297
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
static const Event PageUp
Definition event.hpp:52
static const Event Escape
Definition event.hpp:44
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
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
static const Event ArrowLeft
Definition event.hpp:35
static const Event Delete
Definition event.hpp:42
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