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.
|
|
|
|
|
2018-10-10 01:06:03 +08:00
|
|
|
#include <chrono>
|
2020-05-25 07:34:13 +08:00
|
|
|
#include <ftxui/component/component.hpp>
|
|
|
|
#include <ftxui/component/screen_interactive.hpp>
|
|
|
|
#include <ftxui/screen/string.hpp>
|
2018-10-10 01:06:03 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <thread>
|
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
using namespace ftxui;
|
2019-01-07 00:10:35 +08:00
|
|
|
|
|
|
|
class DrawKey : public Component {
|
2018-10-10 01:06:03 +08:00
|
|
|
public:
|
2019-01-13 01:24:46 +08:00
|
|
|
~DrawKey() override = default;
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
Element Render() override {
|
2019-01-13 01:24:46 +08:00
|
|
|
Elements children;
|
2018-10-10 01:06:03 +08:00
|
|
|
for (size_t i = std::max(0, (int)keys.size() - 10); i < keys.size(); ++i) {
|
2019-06-23 23:47:33 +08:00
|
|
|
std::wstring code;
|
2020-03-27 08:42:46 +08:00
|
|
|
for (auto& it : keys[i].input())
|
2019-06-23 23:59:34 +08:00
|
|
|
code += L" " + std::to_wstring((unsigned int)it);
|
2019-06-23 23:47:33 +08:00
|
|
|
|
2019-07-03 05:09:20 +08:00
|
|
|
code = L"(" + code + L" ) -> ";
|
2021-04-19 00:32:38 +08:00
|
|
|
if (keys[i].is_character()) {
|
|
|
|
code += std::wstring(L"character(") + keys[i].character() + L")";
|
|
|
|
} else if (keys[i].is_mouse_move()) {
|
|
|
|
code += L"mouse_move(" + //
|
|
|
|
std::to_wstring(keys[i].mouse_x()) + L"," +
|
|
|
|
std::to_wstring(keys[i].mouse_y()) + L")";
|
|
|
|
} else if (keys[i].is_mouse_up()) {
|
|
|
|
code += L"mouse_up(" + //
|
|
|
|
std::to_wstring(keys[i].mouse_x()) + L"," +
|
|
|
|
std::to_wstring(keys[i].mouse_y()) + L")";
|
|
|
|
} else if (keys[i].is_mouse_left_down()) {
|
|
|
|
code += L"mouse_left_down(" + //
|
|
|
|
std::to_wstring(keys[i].mouse_x()) + L"," +
|
|
|
|
std::to_wstring(keys[i].mouse_y()) + L")";
|
|
|
|
} else if (keys[i].is_mouse_left_move()) {
|
|
|
|
code += L"mouse_left_move(" + //
|
|
|
|
std::to_wstring(keys[i].mouse_x()) + L"," +
|
|
|
|
std::to_wstring(keys[i].mouse_y()) + L")";
|
2021-04-19 00:42:42 +08:00
|
|
|
} else if (keys[i].is_mouse_middle_down()) {
|
|
|
|
code += L"mouse_middle_down(" + //
|
|
|
|
std::to_wstring(keys[i].mouse_x()) + L"," +
|
|
|
|
std::to_wstring(keys[i].mouse_y()) + L")";
|
|
|
|
} else if (keys[i].is_mouse_middle_move()) {
|
|
|
|
code += L"mouse_middle_move(" + //
|
|
|
|
std::to_wstring(keys[i].mouse_x()) + L"," +
|
|
|
|
std::to_wstring(keys[i].mouse_y()) + L")";
|
2021-04-19 00:32:38 +08:00
|
|
|
} else if (keys[i].is_mouse_right_down()) {
|
|
|
|
code += L"mouse_right_down(" + //
|
|
|
|
std::to_wstring(keys[i].mouse_x()) + L"," +
|
|
|
|
std::to_wstring(keys[i].mouse_y()) + L")";
|
|
|
|
} else if (keys[i].is_mouse_right_move()) {
|
|
|
|
code += L"mouse_right_move(" + //
|
|
|
|
std::to_wstring(keys[i].mouse_x()) + L"," +
|
|
|
|
std::to_wstring(keys[i].mouse_y()) + L")";
|
|
|
|
} else {
|
2020-03-27 08:42:46 +08:00
|
|
|
code += L"(special)";
|
2021-04-19 00:32:38 +08:00
|
|
|
}
|
2019-06-23 23:47:33 +08:00
|
|
|
children.push_back(text(code));
|
2018-10-10 01:06:03 +08:00
|
|
|
}
|
2020-05-21 02:50:40 +08:00
|
|
|
return window(text(L"keys"), vbox(std::move(children)));
|
2018-10-10 01:06:03 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 00:10:35 +08:00
|
|
|
bool OnEvent(Event event) override {
|
2018-10-19 04:58:38 +08:00
|
|
|
keys.push_back(event);
|
2018-10-10 01:06:03 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-01-07 00:10:35 +08:00
|
|
|
std::vector<Event> keys;
|
2018-10-10 01:06:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, const char* argv[]) {
|
2020-05-21 02:50:40 +08:00
|
|
|
auto screen = ScreenInteractive::TerminalOutput();
|
2019-01-13 01:24:46 +08:00
|
|
|
DrawKey draw_key;
|
|
|
|
screen.Loop(&draw_key);
|
2018-10-10 01:06:03 +08:00
|
|
|
}
|