2018-10-10 01:06:03 +08:00
|
|
|
#include <chrono>
|
|
|
|
#include <iostream>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include "ftxui/component/component.hpp"
|
2019-01-07 00:10:35 +08:00
|
|
|
#include "ftxui/component/screen_interactive.hpp"
|
2019-01-13 01:24:46 +08:00
|
|
|
#include "ftxui/screen/string.hpp"
|
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
|
|
|
|
|
|
|
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-01-07 00:10:35 +08:00
|
|
|
std::string code = "";
|
|
|
|
for (size_t j = 0; j < 5; ++j)
|
2018-10-19 04:58:38 +08:00
|
|
|
code += " " + std::to_string(keys[i].values[j]);
|
|
|
|
|
2018-10-10 01:06:03 +08:00
|
|
|
try {
|
2019-01-07 00:10:35 +08:00
|
|
|
std::string line = code + " -> " + std::to_string(keys[i].values[0]) +
|
|
|
|
" (" + char(keys[i].values[0]) + ")";
|
2018-10-10 01:06:03 +08:00
|
|
|
children.push_back(text(to_wstring(line)));
|
|
|
|
} catch (...) {
|
2018-10-19 04:58:38 +08:00
|
|
|
std::string line =
|
|
|
|
code + " -> " + std::to_string(keys[i].values[0]) + " (undefined)";
|
2018-10-10 01:06:03 +08:00
|
|
|
children.push_back(text(to_wstring(line)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return vbox(std::move(children));
|
|
|
|
}
|
|
|
|
|
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[]) {
|
2019-01-07 00:10:35 +08:00
|
|
|
auto screen = ScreenInteractive::FixedSize(80, 10);
|
2019-01-13 01:24:46 +08:00
|
|
|
DrawKey draw_key;
|
|
|
|
screen.Loop(&draw_key);
|
2018-10-10 01:06:03 +08:00
|
|
|
}
|