FTXUI/src/ftxui/component/event.cpp

126 lines
3.3 KiB
C++
Raw Normal View History

#include "ftxui/component/event.hpp"
2020-03-23 05:32:44 +08:00
#include <iostream>
#include "ftxui/screen/string.hpp"
2018-10-19 04:58:38 +08:00
namespace ftxui {
2018-10-19 04:58:38 +08:00
2020-08-09 20:53:56 +08:00
// static
2021-04-19 00:32:38 +08:00
Event Event::Character(std::string input) {
2020-08-09 20:53:56 +08:00
Event event;
event.character_ = to_wstring(input)[0];
2021-04-19 00:32:38 +08:00
event.input_ = std::move(input);
event.type_ = Type::Character;
2020-08-09 20:53:56 +08:00
return event;
}
// static
Event Event::Character(char c) {
return Character(wchar_t(c));
}
// static
Event Event::Character(wchar_t c) {
Event event;
event.input_ = {(char)c};
2021-04-19 00:32:38 +08:00
event.type_ = Type::Character;
2020-08-09 20:53:56 +08:00
event.character_ = c;
return event;
}
// static
2021-04-19 00:32:38 +08:00
Event Event::MouseMove(std::string input, int x, int y) {
Event event;
event.input_ = std::move(input);
event.type_ = Type::MouseMove;
event.mouse_ = {x, y};
return event;
}
// static
Event Event::MouseUp(std::string input, int x, int y) {
Event event;
event.input_ = std::move(input);
event.type_ = Type::MouseUp;
event.mouse_ = {x, y};
return event;
}
// static
Event Event::MouseLeftDown(std::string input, int x, int y) {
Event event;
event.input_ = std::move(input);
event.type_ = Type::MouseLeftDown;
event.mouse_ = {x, y};
return event;
}
// static
Event Event::MouseLeftMove(std::string input, int x, int y) {
Event event;
event.input_ = std::move(input);
event.type_ = Type::MouseLeftMove;
event.mouse_ = {x, y};
return event;
}
// static
Event Event::MouseRightDown(std::string input, int x, int y) {
Event event;
event.input_ = std::move(input);
event.type_ = Type::MouseRightDown;
event.mouse_ = {x, y};
return event;
}
// static
Event Event::MouseRightMove(std::string input, int x, int y) {
Event event;
event.input_ = std::move(input);
event.type_ = Type::MouseRightMove;
event.mouse_ = {x, y};
return event;
}
// static
Event Event::Special(std::string input) {
2020-08-09 20:53:56 +08:00
Event event;
event.input_ = std::move(input);
return event;
}
2018-10-19 04:58:38 +08:00
// --- Arrow ---
2020-10-24 22:47:03 +08:00
const Event Event::ArrowLeft = Event::Special("\x1B[D");
const Event Event::ArrowRight = Event::Special("\x1B[C");
const Event Event::ArrowUp = Event::Special("\x1B[A");
const Event Event::ArrowDown = Event::Special("\x1B[B");
const Event Event::Backspace = Event::Special({127});
const Event Event::Delete = Event::Special("\x1B[3~");
const Event Event::Escape = Event::Special("\x1B");
#if defined(_WIN32)
2020-10-24 22:47:03 +08:00
const Event Event::Return = Event::Special({13});
#else
2020-10-24 22:47:03 +08:00
const Event Event::Return = Event::Special({10});
#endif
2020-10-24 22:47:03 +08:00
const Event Event::Tab = Event::Special({9});
const Event Event::TabReverse = Event::Special({27, 91, 90});
const Event Event::F1 = Event::Special("\x1B[OP");
const Event Event::F2 = Event::Special("\x1B[OQ");
const Event Event::F3 = Event::Special("\x1B[OR");
const Event Event::F4 = Event::Special("\x1B[OS");
const Event Event::F5 = Event::Special("\x1B[15~");
const Event Event::F6 = Event::Special("\x1B[17~");
const Event Event::F7 = Event::Special("\x1B[18~");
const Event Event::F8 = Event::Special("\x1B[19~");
const Event Event::F9 = Event::Special("\x1B[20~");
const Event Event::F10 = Event::Special("\x1B[21~");
const Event Event::F11 = Event::Special("\x1B[21~"); // Doesn't exist
const Event Event::F12 = Event::Special("\x1B[24~");
Event Event::Custom = Event::Special({0});
} // namespace ftxui
// 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.