2020-04-20 03:00:37 +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.
|
|
|
|
|
2021-05-23 18:53:20 +08:00
|
|
|
#include <stddef.h> // for size_t
|
|
|
|
#include <algorithm> // for max
|
2021-08-09 05:25:20 +08:00
|
|
|
#include <memory> // for allocator, shared_ptr
|
|
|
|
#include <string> // for char_traits, operator+, string, basic_string, to_string
|
2021-05-10 02:32:27 +08:00
|
|
|
#include <utility> // for move
|
|
|
|
#include <vector> // for vector
|
2021-05-02 02:40:35 +08:00
|
|
|
|
2021-05-10 02:32:27 +08:00
|
|
|
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
2021-05-23 18:53:20 +08:00
|
|
|
#include "ftxui/component/component.hpp" // for CatchEvent, Renderer
|
2021-05-10 02:32:27 +08:00
|
|
|
#include "ftxui/component/event.hpp" // for Event
|
|
|
|
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Middle, Mouse::None, Mouse::Pressed, Mouse::Released, Mouse::Right, Mouse::WheelDown, Mouse::WheelUp
|
2021-05-23 18:53:20 +08:00
|
|
|
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
|
|
|
#include "ftxui/dom/elements.hpp" // for text, vbox, window, Element, Elements
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
using namespace ftxui;
|
2019-01-07 00:10:35 +08:00
|
|
|
|
2024-04-28 21:17:54 +08:00
|
|
|
std::string Code(Event event) {
|
|
|
|
std::string codes;
|
|
|
|
for (auto& it : event.input()) {
|
|
|
|
codes += " " + std::to_string((unsigned int)it);
|
2021-04-25 21:22:38 +08:00
|
|
|
}
|
2024-04-28 21:17:54 +08:00
|
|
|
return codes;
|
2021-04-25 21:22:38 +08:00
|
|
|
}
|
|
|
|
|
2023-06-03 19:59:39 +08:00
|
|
|
int main() {
|
2021-05-23 18:53:20 +08:00
|
|
|
auto screen = ScreenInteractive::TerminalOutput();
|
|
|
|
|
|
|
|
std::vector<Event> keys;
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2024-04-28 21:17:54 +08:00
|
|
|
auto left_column = Renderer([&] {
|
|
|
|
Elements children = {
|
|
|
|
text("Codes"),
|
|
|
|
separator(),
|
|
|
|
};
|
|
|
|
for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
|
|
|
|
children.push_back(text(Code(keys[i])));
|
|
|
|
}
|
|
|
|
return vbox(children);
|
2021-05-23 18:53:20 +08:00
|
|
|
});
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2024-04-28 21:17:54 +08:00
|
|
|
auto right_column = Renderer([&] {
|
|
|
|
Elements children = {
|
|
|
|
text("Event"),
|
|
|
|
separator(),
|
|
|
|
};
|
|
|
|
for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
|
|
|
|
children.push_back(text(keys[i].DebugString()));
|
|
|
|
}
|
|
|
|
return vbox(children);
|
|
|
|
});
|
|
|
|
|
|
|
|
int split_size = 40;
|
|
|
|
auto component = ResizableSplitLeft(left_column, right_column, &split_size);
|
|
|
|
component |= border;
|
|
|
|
|
2022-03-12 22:18:36 +08:00
|
|
|
component |= CatchEvent([&](Event event) {
|
2018-10-19 04:58:38 +08:00
|
|
|
keys.push_back(event);
|
2024-04-28 21:17:54 +08:00
|
|
|
return false;
|
2021-05-23 18:53:20 +08:00
|
|
|
});
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2021-05-23 18:53:20 +08:00
|
|
|
screen.Loop(component);
|
2018-10-10 01:06:03 +08:00
|
|
|
}
|