mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-10-31 00:17:44 +08:00
42 lines
967 B
C++
42 lines
967 B
C++
#include <chrono>
|
|
#include <iostream>
|
|
#include <thread>
|
|
|
|
#include "ftxui/component/component.hpp"
|
|
#include "ftxui/component/screen_interactive.hpp"
|
|
#include "ftxui/screen/string.hpp"
|
|
|
|
using namespace ftxui;
|
|
|
|
class DrawKey : public Component {
|
|
public:
|
|
~DrawKey() override = default;
|
|
|
|
Element Render() override {
|
|
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);
|
|
|
|
code = L"(" + code + L" ) -> " + keys[i].character() + L")";
|
|
children.push_back(text(code));
|
|
}
|
|
return vbox(std::move(children));
|
|
}
|
|
|
|
bool OnEvent(Event event) override {
|
|
keys.push_back(event);
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
std::vector<Event> keys;
|
|
};
|
|
|
|
int main(int argc, const char* argv[]) {
|
|
auto screen = ScreenInteractive::FixedSize(80, 10);
|
|
DrawKey draw_key;
|
|
screen.Loop(&draw_key);
|
|
}
|