13#pragma clang diagnostic ignored "-Wshadow"
15#pragma GCC diagnostic ignored "-Wshadow"
16#elif defined(_MSC_VER)
17#pragma warning(disable : 6244)
18#pragma warning(disable : 6246)
26Event Event::Character(std::string input) {
28 event.input_ = std::move(
input);
29 event.type_ = Type::Character;
37 return Event::Character(std::string{
c});
43Event Event::Character(
wchar_t c) {
44 return Event::Character(
to_string(std::wstring{
c}));
51Event Event::Mouse(std::string input,
struct Mouse mouse) {
53 event.input_ = std::move(
input);
54 event.type_ = Type::Mouse;
55 event.data_.mouse =
mouse;
61Event Event::CursorShape(std::string input,
int shape) {
63 event.input_ = std::move(
input);
64 event.type_ = Type::CursorShape;
65 event.data_.cursor_shape = shape;
74 event.input_ = std::move(
input);
80Event Event::CursorPosition(std::string input,
int x,
int y) {
82 event.input_ = std::move(
input);
83 event.type_ = Type::CursorPosition;
84 event.data_.cursor = {
x,
y};
90 static std::map<Event, const char*> event_to_string = {
220 static std::map<Mouse::Button, const char*> mouse_button_string = {
231 static std::map<Mouse::Motion, const char*> mouse_motion_string = {
238 case Type::Character: {
239 return "Event::Character(\"" + input_ +
"\")";
242 std::string out =
"Event::Mouse(\"...\", Mouse{";
243 out += std::string(mouse_button_string[data_.mouse.button]);
245 out += std::string(mouse_motion_string[data_.mouse.motion]);
247 if (data_.mouse.shift) {
248 out +=
".shift = true, ";
250 if (data_.mouse.meta) {
251 out +=
".meta = true, ";
253 if (data_.mouse.control) {
254 out +=
".control = true, ";
256 out +=
".x = " + std::to_string(data_.mouse.x);
258 out +=
".y = " + std::to_string(data_.mouse.y);
262 case Type::CursorShape:
263 return "Event::CursorShape(" + input_ +
", " +
264 std::to_string(data_.cursor_shape) +
")";
265 case Type::CursorPosition:
266 return "Event::CursorPosition(" + input_ +
", " +
267 std::to_string(data_.cursor.x) +
", " +
268 std::to_string(data_.cursor.y) +
")";
270 auto event_it = event_to_string.find(*
this);
271 if (event_it != event_to_string.end()) {
272 return event_it->second;
322const Event
Event::a = Event::Character(
"a");
323const Event
Event::b = Event::Character(
"b");
324const Event
Event::c = Event::Character(
"c");
325const Event
Event::d = Event::Character(
"d");
326const Event
Event::e = Event::Character(
"e");
327const Event
Event::f = Event::Character(
"f");
328const Event
Event::g = Event::Character(
"g");
329const Event
Event::h = Event::Character(
"h");
330const Event
Event::i = Event::Character(
"i");
331const Event
Event::j = Event::Character(
"j");
332const Event
Event::k = Event::Character(
"k");
333const Event
Event::l = Event::Character(
"l");
334const Event
Event::m = Event::Character(
"m");
335const Event
Event::n = Event::Character(
"n");
336const Event
Event::o = Event::Character(
"o");
337const Event
Event::p = Event::Character(
"p");
338const Event
Event::q = Event::Character(
"q");
339const Event
Event::r = Event::Character(
"r");
340const Event
Event::s = Event::Character(
"s");
341const Event
Event::t = Event::Character(
"t");
342const Event
Event::u = Event::Character(
"u");
343const Event
Event::v = Event::Character(
"v");
344const Event
Event::w = Event::Character(
"w");
345const Event
Event::x = Event::Character(
"x");
346const Event
Event::y = Event::Character(
"y");
347const Event
Event::z = Event::Character(
"z");
349const Event
Event::A = Event::Character(
"A");
350const Event
Event::B = Event::Character(
"B");
351const Event
Event::C = Event::Character(
"C");
352const Event
Event::D = Event::Character(
"D");
353const Event
Event::E = Event::Character(
"E");
354const Event
Event::F = Event::Character(
"F");
355const Event
Event::G = Event::Character(
"G");
356const Event
Event::H = Event::Character(
"H");
357const Event
Event::I = Event::Character(
"I");
358const Event
Event::J = Event::Character(
"J");
359const Event
Event::K = Event::Character(
"K");
360const Event
Event::L = Event::Character(
"L");
361const Event
Event::M = Event::Character(
"M");
362const Event
Event::N = Event::Character(
"N");
363const Event
Event::O = Event::Character(
"O");
364const Event
Event::P = Event::Character(
"P");
365const Event
Event::Q = Event::Character(
"Q");
366const Event
Event::R = Event::Character(
"R");
367const Event
Event::S = Event::Character(
"S");
368const Event
Event::T = Event::Character(
"T");
369const Event
Event::U = Event::Character(
"U");
370const Event
Event::V = Event::Character(
"V");
371const Event
Event::W = Event::Character(
"W");
372const Event
Event::X = Event::Character(
"X");
373const Event
Event::Y = Event::Character(
"Y");
374const Event
Event::Z = Event::Character(
"Z");
static const Event TabReverse
static const Event ArrowLeftCtrl
static const Event CtrlAltX
static const Event CtrlAltN
static const Event CtrlAltC
static const Event PageUp
static const Event CtrlAltF
static const Event Escape
static const Event CtrlAltI
static const Event CtrlAltP
static const Event CtrlAltE
static const Event CtrlAltJ
static const Event CtrlAltH
static const Event CtrlAltW
static const Event CtrlAltO
static const Event Custom
std::string DebugString() const
返回事件的字符串表示。
static const Event CtrlAltM
static const Event Backspace
static const Event CtrlAltR
static const Event ArrowUp
const std::string & input() const
static const Event CtrlAltZ
static const Event ArrowDown
static const Event CtrlAltY
static const Event CtrlAltL
static const Event ArrowUpCtrl
static const Event CtrlAltS
static const Event PageDown
static const Event CtrlAltK
static const Event CtrlAltG
static const Event Return
static const Event CtrlAltU
static const Event CtrlAltT
static const Event CtrlAltA
static const Event ArrowLeft
static const Event CtrlAltB
static const Event Delete
static const Event CtrlAltV
static const Event ArrowDownCtrl
static const Event CtrlAltD
static const Event Insert
static const Event ArrowRightCtrl
static const Event CtrlAltQ
static Event Special(std::string)
一个自定义事件,其含义由库用户定义。
static const Event ArrowRight
代表一个事件。它可以是按键事件、终端大小调整等等...
一个鼠标事件。它包含鼠标的坐标、按下的按钮以及修饰符(shift、ctrl、meta)。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::string to_string(const std::wstring &s)
将 std::wstring 转换为 UTF8 std::string。