#include <stddef.h>
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
std::string Stringify(Event event) {
std::string out;
for (auto& it : event.input())
out = "(" + out + " ) -> ";
if (event.is_character()) {
out += "Event::Character(\"" + event.character() + "\")";
} else if (event.is_mouse()) {
out += "mouse";
switch (event.mouse().button) {
out += "_left";
break;
out += "_middle";
break;
out += "_right";
break;
out += "_none";
break;
out += "_wheel_up";
break;
out += "_wheel_down";
break;
}
switch (event.mouse().motion) {
out += "_pressed";
break;
out += "_released";
break;
out += "_moved";
break;
}
if (event.mouse().control)
out += "_control";
if (event.mouse().shift)
out += "_shift";
if (event.mouse().meta)
out += "_meta";
out += "(" +
out += "Event::ArrowLeft";
out += "Event::ArrowRight";
out += "Event::ArrowUp";
out += "Event::ArrowDown";
out += "Event::ArrowLeftCtrl";
out += "Event::ArrowRightCtrl";
out += "Event::ArrowUpCtrl";
out += "Event::ArrowDownCtrl";
out += "Event::Backspace";
out += "Event::Delete";
out += "Event::Escape";
out += "Event::Return";
out += "Event::Tab";
out += "Event::TabReverse";
out += "Event::F1";
out += "Event::F2";
out += "Event::F3";
out += "Event::F4";
out += "Event::F5";
out += "Event::F6";
out += "Event::F7";
out += "Event::F8";
out += "Event::F9";
out += "Event::F10";
out += "Event::F11";
out += "Event::F12";
out += "Event::Home";
out += "Event::End";
out += "Event::PageUp";
out += "Event::PageDown";
out += "Custom";
} else {
out += "(special)";
}
return out;
}
int main() {
std::vector<Event> keys;
for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i)
children.push_back(
text(Stringify(keys[i])));
});
keys.push_back(event);
return true;
});
screen.Loop(component);
}
static ScreenInteractive TerminalOutput()
Element window(Element title, Element content)
Draw window with a title and a border around the element.
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
std::string to_string(const std::wstring &s)
Convert a UTF8 std::string into a std::wstring.
Element text(std::wstring text)
Display a piece of unicode text.
std::vector< Element > Elements
Component CatchEvent(Component child, std::function< bool(Event)>)
Element vbox(Elements)
A container displaying elements vertically one by one.
static const Event TabReverse
static const Event ArrowLeftCtrl
static const Event PageUp
static const Event Escape
static const Event Custom
static const Event Backspace
static const Event ArrowUp
static const Event ArrowDown
static const Event ArrowUpCtrl
static const Event PageDown
static const Event Return
static const Event ArrowLeft
static const Event Delete
static const Event ArrowDownCtrl
static const Event ArrowRightCtrl
static const Event ArrowRight