2018-10-10 01:06:03 +08:00
|
|
|
#include <chrono>
|
|
|
|
#include <iostream>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include "ftxui/screen_interactive.hpp"
|
|
|
|
#include "ftxui/component/component.hpp"
|
|
|
|
#include "ftxui/util/string.hpp"
|
|
|
|
|
|
|
|
class DrawKey : public ftxui::component::Component {
|
|
|
|
public:
|
|
|
|
DrawKey(ftxui::component::Delegate* delegate)
|
|
|
|
: ftxui::component::Component(delegate) {}
|
|
|
|
|
|
|
|
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) {
|
2018-10-19 04:58:38 +08:00
|
|
|
std::string code = "";
|
|
|
|
for(size_t j = 0; j<5; ++j)
|
|
|
|
code += " " + std::to_string(keys[i].values[j]);
|
|
|
|
|
2018-10-10 01:06:03 +08:00
|
|
|
try {
|
2018-10-19 04:58:38 +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));
|
|
|
|
}
|
|
|
|
|
2018-10-19 04:58:38 +08:00
|
|
|
bool OnEvent(ftxui::Event event) override {
|
|
|
|
keys.push_back(event);
|
2018-10-10 01:06:03 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-10-19 04:58:38 +08:00
|
|
|
std::vector<ftxui::Event> keys;
|
2018-10-10 01:06:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, const char* argv[]) {
|
|
|
|
ftxui::ScreenInteractive screen(80,10);
|
|
|
|
DrawKey draw_key(screen.delegate());
|
|
|
|
screen.Loop();
|
|
|
|
}
|