FTXUI/examples/util/print_key_press.cpp

46 lines
1.0 KiB
C++
Raw Normal View History

#include <chrono>
#include <iostream>
#include <thread>
#include "ftxui/component/component.hpp"
#include "ftxui/component/screen_interactive.hpp"
2019-01-13 01:24:46 +08:00
#include "ftxui/screen/string.hpp"
using namespace ftxui;
class DrawKey : public Component {
public:
2019-01-13 01:24:46 +08:00
~DrawKey() override = default;
Element Render() override {
2019-01-13 01:24:46 +08:00
Elements children;
for (size_t i = std::max(0, (int)keys.size() - 10); i < keys.size(); ++i) {
std::wstring code;
for(auto& it : keys[i].input())
code += L" " + std::to_wstring((unsigned int)it);
2019-07-03 05:09:20 +08:00
code = L"(" + code + L" ) -> ";
if (keys[i].is_character())
code += keys[i].character();
else
code += L"(special)";
children.push_back(text(code));
}
return vbox(std::move(children));
}
bool OnEvent(Event event) override {
2018-10-19 04:58:38 +08:00
keys.push_back(event);
return true;
}
private:
std::vector<Event> keys;
};
int main(int argc, const char* argv[]) {
auto screen = ScreenInteractive::FixedSize(80, 10);
2019-01-13 01:24:46 +08:00
DrawKey draw_key;
screen.Loop(&draw_key);
}