2021-05-09 20:32:27 +02:00
|
|
|
#include <utility> // for move
|
2020-03-22 22:32:44 +01:00
|
|
|
|
2021-05-09 20:32:27 +02:00
|
|
|
#include "ftxui/component/event.hpp"
|
|
|
|
#include "ftxui/component/mouse.hpp" // for Mouse
|
|
|
|
#include "ftxui/screen/string.hpp" // for to_wstring
|
2018-10-18 22:58:38 +02:00
|
|
|
|
2019-01-12 15:00:08 +01:00
|
|
|
namespace ftxui {
|
2018-10-18 22:58:38 +02:00
|
|
|
|
2020-08-09 14:53:56 +02:00
|
|
|
// static
|
2021-04-18 18:32:38 +02:00
|
|
|
Event Event::Character(std::string input) {
|
2020-08-09 14:53:56 +02:00
|
|
|
Event event;
|
2021-04-18 18:32:38 +02:00
|
|
|
event.input_ = std::move(input);
|
|
|
|
event.type_ = Type::Character;
|
2020-08-09 14:53:56 +02:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
Event Event::Character(char c) {
|
2021-08-08 23:25:20 +02:00
|
|
|
return Event::Character(std::string{c});
|
2020-08-09 14:53:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
Event Event::Character(wchar_t c) {
|
2021-08-08 23:25:20 +02:00
|
|
|
return Event::Character(to_string(std::wstring{c}));
|
2020-08-09 14:53:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2021-04-25 15:22:38 +02:00
|
|
|
Event Event::Mouse(std::string input, struct Mouse mouse) {
|
2021-04-18 18:32:38 +02:00
|
|
|
Event event;
|
|
|
|
event.input_ = std::move(input);
|
2021-04-25 15:22:38 +02:00
|
|
|
event.type_ = Type::Mouse;
|
2022-03-31 02:17:43 +02:00
|
|
|
event.mouse_ = mouse; // NOLINT
|
2021-04-18 18:42:42 +02:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
Event Event::Special(std::string input) {
|
|
|
|
Event event;
|
|
|
|
event.input_ = std::move(input);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2021-04-18 18:32:38 +02:00
|
|
|
// static
|
2021-04-24 18:16:13 +02: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 02:17:43 +02:00
|
|
|
event.cursor_.x = x; // NOLINT
|
|
|
|
event.cursor_.y = y; // NOLINT
|
2021-04-24 18:16:13 +02:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2018-10-18 22:58:38 +02:00
|
|
|
// --- Arrow ---
|
2022-10-06 21:16:55 +02: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-18 22:58:22 +02: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 02:17:43 +02:00
|
|
|
const Event Event::F12 = Event::Special("\x1B[24~"); // NOLINT
|
2022-10-18 22:58:22 +02:00
|
|
|
|
2022-03-31 02:17:43 +02: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 17:47:33 +02:00
|
|
|
|
|
|
|
} // namespace ftxui
|
2020-08-16 00:24:18 +02: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.
|