FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
print_key_press.cpp
浏览该文件的文档.
1// 版权所有 2020 Arthur Sonzogni. 保留所有权利。
2// 本源代码的使用受 MIT 许可证的约束,该许可证可在
3// LICENSE 文件中找到。
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
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() {
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}
static ScreenInteractive TerminalOutput()
const std::string & input() const
Component Renderer(Component child, std::function< Element()>)
返回一个新组件,类似于 |child|,但使用 |render| 作为 Component::Render() 事件。
Component ResizableSplitLeft(Component main, Component back, int *main_size)
两个组件之间的水平分割,可通过鼠标配置。
代表一个事件。它可以是按键事件、终端大小调整等等...
Element text(std::wstring text)
显示一段Unicode文本。
Element separator()
在两个其他元素之间绘制垂直或水平分隔线。
Element vbox(Elements)
垂直一个接一个显示元素的容器。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::vector< Element > Elements
Element border(Element)
Component CatchEvent(Component child, std::function< bool(Event)>)
std::string Code(Event event)