print_key_press
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
std::string codes;
for (
auto& it : event.
input()) {
codes += " " + std::to_string((unsigned int)it);
}
return codes;
}
auto screen = ScreenInteractive::TerminalOutput();
std::vector<Event> keys;
auto left_column = Renderer([&] {
text("Codes"),
separator(),
};
for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
children.push_back(
text(
Code(keys[i])));
}
});
};
for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
children.push_back(
text(keys[i].DebugString()));
}
});
int split_size = 40;
keys.push_back(event);
return false;
});
screen.Loop(component);
}
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
std::vector< Element > Elements
Element text(std::wstring text)
Display a piece of unicode text.
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Component ResizableSplitLeft(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
Element border(Element)
Draw a border around the element.
Component CatchEvent(Component child, std::function< bool(Event)>)
Element vbox(Elements)
A container displaying elements vertically one by one.
std::string Code(Event event)
Represent an event. It can be key press event, a terminal resize, or more ...
const std::string & input() const
#include <memory>
#include <string>
void Nested(std::string path) {
auto screen = ScreenInteractive::FitComponent();
auto back_button = Button("Back", screen.ExitLoopClosure());
auto goto_1 = Button(
"Goto /1", [path] {
Nested(path +
"/1"); });
auto goto_2 = Button(
"Goto /2", [path] {
Nested(path +
"/2"); });
auto goto_3 = Button(
"Goto /3", [path] {
Nested(path +
"/3"); });
auto layout = Container::Vertical({
back_button,
goto_1,
goto_2,
goto_3,
});
auto renderer = Renderer(layout, [&] {
return vbox({
text("path: " + path),
separator(),
back_button->Render(),
goto_1->Render(),
goto_2->Render(),
goto_3->Render(),
}) |
border;
});
screen.Loop(renderer);
}
auto screen = ScreenInteractive::FitComponent();
auto button_quit = Button("Quit", screen.ExitLoopClosure());
auto button_nested = Button(
"Nested", [] {
Nested(
""); });
screen.Loop(Container::Vertical({
button_quit,
button_nested,
}));
return 0;
}
void Nested(std::string path)