2021-05-10 02:32:27 +08:00
|
|
|
#include <utility> // for move
|
2020-03-23 05:32:44 +08:00
|
|
|
|
2021-05-10 02:32:27 +08:00
|
|
|
#include "ftxui/component/event.hpp"
|
|
|
|
#include "ftxui/component/mouse.hpp" // for Mouse
|
|
|
|
#include "ftxui/screen/string.hpp" // for to_wstring
|
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;
|
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) {
|
2021-08-09 05:25:20 +08:00
|
|
|
return Event::Character(std::string{c});
|
2020-08-09 20:53:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
Event Event::Character(wchar_t c) {
|
2021-08-09 05:25:20 +08:00
|
|
|
return Event::Character(to_string(std::wstring{c}));
|
2020-08-09 20:53:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2022-03-31 08:17:43 +08:00
|
|
|
event.mouse_ = mouse; // NOLINT
|
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;
|
2022-03-31 08:17:43 +08:00
|
|
|
event.cursor_.x = x; // NOLINT
|
|
|
|
event.cursor_.y = y; // NOLINT
|
2021-04-25 00:16:13 +08:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2018-10-19 04:58:38 +08:00
|
|
|
// --- Arrow ---
|
2022-10-07 03:16:55 +08:00
|
|
|
const Event Event::ArrowLeft = Event::Special("\x1B[D"); // NOLINT
|
|
|
|
const Event Event::ArrowRight = Event::Special("\x1B[C"); // NOLINT
|
|
|
|
const Event Event::ArrowUp = Event::Special("\x1B[A"); // NOLINT
|
|
|
|
const Event Event::ArrowDown = Event::Special("\x1B[B"); // NOLINT
|
|
|
|
const Event Event::ArrowLeftCtrl = Event::Special("\x1B[1;5D"); // NOLINT
|
|
|
|
const Event Event::ArrowRightCtrl = Event::Special("\x1B[1;5C"); // NOLINT
|
|
|
|
const Event Event::ArrowUpCtrl = Event::Special("\x1B[1;5A"); // NOLINT
|
|
|
|
const Event Event::ArrowDownCtrl = Event::Special("\x1B[1;5B"); // NOLINT
|
|
|
|
const Event Event::Backspace = Event::Special({127}); // NOLINT
|
|
|
|
const Event Event::Delete = Event::Special("\x1B[3~"); // NOLINT
|
|
|
|
const Event Event::Escape = Event::Special("\x1B"); // NOLINT
|
|
|
|
const Event Event::Return = Event::Special({10}); // NOLINT
|
|
|
|
const Event Event::Tab = Event::Special({9}); // NOLINT
|
|
|
|
const Event Event::TabReverse = Event::Special({27, 91, 90}); // NOLINT
|
2022-10-19 04:58:22 +08:00
|
|
|
|
|
|
|
// See https://invisible-island.net/xterm/xterm-function-keys.html
|
|
|
|
// We follow xterm-new / vterm-xf86-v4 / mgt / screen
|
|
|
|
const Event Event::F1 = Event::Special("\x1BOP"); // NOLINT
|
|
|
|
const Event Event::F2 = Event::Special("\x1BOQ"); // NOLINT
|
|
|
|
const Event Event::F3 = Event::Special("\x1BOR"); // NOLINT
|
|
|
|
const Event Event::F4 = Event::Special("\x1BOS"); // NOLINT
|
|
|
|
const Event Event::F5 = Event::Special("\x1B[15~"); // NOLINT
|
|
|
|
const Event Event::F6 = Event::Special("\x1B[17~"); // NOLINT
|
|
|
|
const Event Event::F7 = Event::Special("\x1B[18~"); // NOLINT
|
|
|
|
const Event Event::F8 = Event::Special("\x1B[19~"); // NOLINT
|
|
|
|
const Event Event::F9 = Event::Special("\x1B[20~"); // NOLINT
|
|
|
|
const Event Event::F10 = Event::Special("\x1B[21~"); // NOLINT
|
|
|
|
const Event Event::F11 = Event::Special("\x1B[23~"); // NOLINT
|
2022-03-31 08:17:43 +08:00
|
|
|
const Event Event::F12 = Event::Special("\x1B[24~"); // NOLINT
|
2022-10-19 04:58:22 +08:00
|
|
|
|
2022-03-31 08:17:43 +08:00
|
|
|
const Event Event::Home = Event::Special({27, 91, 72}); // NOLINT
|
|
|
|
const Event Event::End = Event::Special({27, 91, 70}); // NOLINT
|
|
|
|
const Event Event::PageUp = Event::Special({27, 91, 53, 126}); // NOLINT
|
|
|
|
const Event Event::PageDown = Event::Special({27, 91, 54, 126}); // NOLINT
|
|
|
|
const Event Event::Custom = Event::Special({0}); // NOLINT
|
2019-06-23 23:47:33 +08:00
|
|
|
|
|
|
|
} // 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.
|