2019-01-07 00:10:35 +08:00
|
|
|
#include "ftxui/component/event.hpp"
|
2020-03-23 05:32:44 +08:00
|
|
|
|
2021-05-02 02:40:35 +08:00
|
|
|
#include "ftxui/component/mouse.hpp"
|
2019-06-23 23:47:33 +08:00
|
|
|
#include "ftxui/screen/string.hpp"
|
2018-10-19 04:58:38 +08:00
|
|
|
|
2019-01-12 22:00:08 +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-25 21:22:38 +08:00
|
|
|
Event Event::Mouse(std::string input, struct Mouse mouse) {
|
2021-04-19 00:32:38 +08:00
|
|
|
Event event;
|
|
|
|
event.input_ = std::move(input);
|
2021-04-25 21:22:38 +08:00
|
|
|
event.type_ = Type::Mouse;
|
|
|
|
event.mouse_ = mouse;
|
2021-04-19 00:42:42 +08:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
Event Event::Special(std::string input) {
|
|
|
|
Event event;
|
|
|
|
event.input_ = std::move(input);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2021-04-19 00:32:38 +08:00
|
|
|
// static
|
2021-04-25 00:16:13 +08:00
|
|
|
Event Event::CursorReporting(std::string input, int x, int y) {
|
|
|
|
Event event;
|
|
|
|
event.input_ = std::move(input);
|
|
|
|
event.type_ = Type::CursorReporting;
|
2021-04-25 21:22:38 +08:00
|
|
|
event.cursor_.x = x;
|
|
|
|
event.cursor_.y = y;
|
2021-04-25 00:16:13 +08:00
|
|
|
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");
|
2020-07-22 01:04:43 +08:00
|
|
|
#if defined(_WIN32)
|
2020-10-24 22:47:03 +08:00
|
|
|
const Event Event::Return = Event::Special({13});
|
2020-07-22 01:04:43 +08:00
|
|
|
#else
|
2020-10-24 22:47:03 +08:00
|
|
|
const Event Event::Return = Event::Special({10});
|
2020-07-22 01:04:43 +08:00
|
|
|
#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~");
|
2021-03-28 08:01:04 +08:00
|
|
|
const Event Event::Home = Event::Special({27, 91, 72});
|
|
|
|
const Event Event::End = Event::Special({27, 91, 70});
|
|
|
|
const Event Event::PageUp = Event::Special({27, 91, 53, 126});
|
|
|
|
const Event Event::PageDown = Event::Special({27, 91, 54, 126});
|
|
|
|
|
2019-06-23 23:47:33 +08:00
|
|
|
Event Event::Custom = Event::Special({0});
|
|
|
|
|
|
|
|
} // namespace ftxui
|
2020-08-16 06:24:18 +08:00
|
|
|
|
|
|
|
// 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.
|