FTXUI 6.1.9 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/captured_mouse.hpp" // for ftxui
13#include "ftxui/component/component.hpp" // for CatchEvent, Renderer
14#include "ftxui/component/event.hpp" // for Event
15#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Middle, Mouse::None, Mouse::Pressed, Mouse::Released, Mouse::Right, Mouse::WheelDown, Mouse::WheelUp
16#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
17#include "ftxui/dom/elements.hpp" // for text, vbox, window, Element, Elements
18
19 using 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
29 int main() {
30 auto screen = ScreenInteractive::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}
captured_mouse.hpp
component.hpp
elements.hpp
event.hpp
ftxui::ScreenInteractive::TerminalOutput
static ScreenInteractive TerminalOutput()
Definition screen_interactive.cpp:410
ftxui::Event::input
const std::string & input() const
Definition event.hpp:104
ftxui::Renderer
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Definition src/ftxui/component/renderer.cpp:61
ftxui::ResizableSplitLeft
Component ResizableSplitLeft(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
Definition src/ftxui/component/resizable_split.cpp:215
ftxui::Event
Represent an event. It can be key press event, a terminal resize, or more ...
Definition event.hpp:29
ftxui::text
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
ftxui::separator
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Definition src/ftxui/dom/separator.cpp:134
ftxui::border
Element border(Element)
Draw a border around the element.
Definition src/ftxui/dom/border.cpp:227
ftxui::vbox
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
mouse.hpp
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::Elements
std::vector< Element > Elements
Definition elements.hpp:23
ftxui::CatchEvent
Component CatchEvent(Component child, std::function< bool(Event)>)
Code
std::string Code(Event event)
Definition print_key_press.cpp:21
main
int main()
Definition print_key_press.cpp:29
screen_interactive.hpp