FTXUI
6.1.9
C++ functional terminal UI.
Toggle main menu visibility
Loading...
Searching...
No Matches
examples/component/print_key_press.cpp
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <stddef.h>
// for size_t
#include <algorithm>
// for max
#include <memory>
// for allocator, shared_ptr
#include <string>
// for char_traits, operator+, string, basic_string, to_string
#include <utility>
// for move
#include <vector>
// for vector
#include "
ftxui/component/captured_mouse.hpp
"
// for ftxui
#include "
ftxui/component/component.hpp
"
// for CatchEvent, Renderer
#include "
ftxui/component/event.hpp
"
// for Event
#include "
ftxui/component/mouse.hpp
"
// for Mouse, Mouse::Left, Mouse::Middle, Mouse::None, Mouse::Pressed, Mouse::Released, Mouse::Right, Mouse::WheelDown, Mouse::WheelUp
#include "
ftxui/component/screen_interactive.hpp
"
// for ScreenInteractive
#include "
ftxui/dom/elements.hpp
"
// for text, vbox, window, Element, Elements
using namespace
ftxui
;
std::string Code(
Event
event) {
std::string codes;
for
(
auto
& it : event.
input
()) {
codes +=
" "
+ std::to_string((
unsigned
int
)it);
}
return
codes;
}
int
main() {
auto
screen =
ScreenInteractive::TerminalOutput
();
std::vector<Event> keys;
auto
left_column =
Renderer
([&] {
Elements
children = {
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])));
}
return
vbox
(children);
});
auto
right_column =
Renderer
([&] {
Elements
children = {
text
(
"Event"
),
separator
(),
};
for
(
size_t
i = std::max(0, (
int
)keys.size() - 20); i < keys.size(); ++i) {
children.push_back(
text
(keys[i].DebugString()));
}
return
vbox
(children);
});
int
split_size = 40;
auto
component =
ResizableSplitLeft
(left_column, right_column, &split_size);
component |=
border
;
component |=
CatchEvent
([&](
Event
event) {
keys.push_back(event);
return
false
;
});
screen.Loop(component);
}
captured_mouse.hpp
ftxui::ScreenInteractive::TerminalOutput
static ScreenInteractive TerminalOutput()
Definition
screen_interactive.cpp:406
component.hpp
elements.hpp
event.hpp
mouse.hpp
ftxui
Definition
animation.hpp:10
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
renderer.cpp:61
ftxui::Elements
std::vector< Element > Elements
Definition
elements.hpp:23
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
separator.cpp:134
ftxui::ResizableSplitLeft
Component ResizableSplitLeft(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
Definition
resizable_split.cpp:215
ftxui::border
Element border(Element)
Draw a border around the element.
Definition
border.cpp:227
ftxui::CatchEvent
Component CatchEvent(Component child, std::function< bool(Event)>)
ftxui::vbox
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition
vbox.cpp:96
screen_interactive.hpp
ftxui::Event
Represent an event. It can be key press event, a terminal resize, or more ...
Definition
event.hpp:27
ftxui::Event::input
const std::string & input() const
Definition
event.hpp:102