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"
|
2018-10-10 01:06:03 +08:00
|
|
|
#include "ftxui/util/string.hpp"
|
|
|
|
|
2019-01-07 00:10:35 +08:00
|
|
|
using namespace ftxui::component;
|
|
|
|
|
|
|
|
class DrawKey : public Component {
|
2018-10-10 01:06:03 +08:00
|
|
|
public:
|
2019-01-07 00:10:35 +08:00
|
|
|
DrawKey(Delegate* delegate)
|
|
|
|
: Component(delegate) {}
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
ftxui::dom::Element Render() override {
|
|
|
|
using namespace ftxui::dom;
|
|
|
|
Children children;
|
|
|
|
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);
|
2018-10-10 01:06:03 +08:00
|
|
|
DrawKey draw_key(screen.delegate());
|
|
|
|
screen.Loop();
|
|
|
|
}
|