FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
print_key_press.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4
5#include <stddef.h> // for size_t
6#include <algorithm> // for max
7#include <memory> // for allocator, shared_ptr
8#include <string> // for char_traits, operator+, string, basic_string, to_string
9#include <utility> // for move
10#include <vector> // for vector
11
12#include "ftxui/component/app.hpp" // for App
13#include "ftxui/component/captured_mouse.hpp" // for ftxui
14#include "ftxui/component/component.hpp" // for CatchEvent, Renderer
15#include "ftxui/component/event.hpp" // for Event
16#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Middle, Mouse::None, Mouse::Pressed, Mouse::Released, Mouse::Right, Mouse::WheelDown, Mouse::WheelUp
17#include "ftxui/dom/elements.hpp" // for text, vbox, window, Element, Elements
18
19using namespace ftxui;
20
21std::string Code(Event event) {
22 std::string codes;
23 for (auto& it : event.input()) {
24 codes += " " + std::to_string((unsigned int)it);
25 }
26 return codes;
27}
28
29int main() {
30 auto screen = App::TerminalOutput();
31
32 std::vector<Event> keys;
33
34 auto left_column = Renderer([&] {
35 Elements children = {
36 text("Codes"),
37 separator(),
38 };
39 for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
40 children.push_back(text(Code(keys[i])));
41 }
42 return vbox(children);
43 });
44
45 auto right_column = Renderer([&] {
46 Elements children = {
47 text("Event"),
48 separator(),
49 };
50 for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
51 children.push_back(text(keys[i].DebugString()));
52 }
53 return vbox(children);
54 });
55
56 int split_size = 40;
57 auto component = ResizableSplitLeft(left_column, right_column, &split_size);
58 component |= border;
59
60 component |= CatchEvent([&](Event event) {
61 keys.push_back(event);
62 return false;
63 });
64
65 screen.Loop(component);
66}
Component Renderer(Component child, std::function< Element()>)
Retourne un nouveau Component, similaire à |child|, mais utilisant |render| comme événement Component...
Component ResizableSplitLeft(Component main, Component back, int *main_size)
Une division horizontale entre deux composants, configurable en utilisant la souris.
Element text(std::string_view text)
Affiche un morceau de texte unicode encodé en UTF8.
Element separator()
Dessine une séparation verticale ou horizontale entre deux autres éléments.
Element border(Element child)
Dessine une bordure autour de l'élément.
Element vbox(Elements children)
Un conteneur affichant les éléments verticalement un par un.
Definition vbox.cpp:96
L'espace de noms FTXUI ftxui::
Definition animation.hpp:11
std::vector< Element > Elements
Definition elements.hpp:26
Component CatchEvent(Component child, std::function< bool(Event)>)
std::string Code(Event event)
int main()