FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
print_key_press.cpp
Go to the documentation of this file.
1// 版權所有 2020 Arthur Sonzogni. 保留所有權利。
2// 本原始碼的使用受 MIT 授權條款約束,該條款可在 LICENSE 檔案中找到。
3
4#include <stddef.h> // for size_t
5#include <algorithm> // for max
6#include <memory> // for allocator, shared_ptr
7#include <string> // for char_traits, operator+, string, basic_string, to_string
8#include <utility> // for move
9#include <vector> // for vector
10
11#include "ftxui/component/captured_mouse.hpp" // for ftxui
12#include "ftxui/component/component.hpp" // for CatchEvent, Renderer
13#include "ftxui/component/event.hpp" // for Event
14#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Middle, Mouse::None, Mouse::Pressed, Mouse::Released, Mouse::Right, Mouse::WheelDown, Mouse::WheelUp
15#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
16#include "ftxui/dom/elements.hpp" // for text, vbox, window, Element, Elements
17
18using namespace ftxui;
19
20std::string Code(Event event) {
21 std::string codes;
22 for (auto& it : event.input()) {
23 codes += " " + std::to_string((unsigned int)it);
24 }
25 return codes;
26}
27
28int main() {
30
31 std::vector<Event> keys;
32
33 auto left_column = Renderer([&] {
34 Elements children = {
35 text("Codes"),
36 separator(),
37 };
38 for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
39 children.push_back(text(Code(keys[i])));
40 }
41 return vbox(children);
42 });
43
44 auto right_column = Renderer([&] {
45 Elements children = {
46 text("Event"),
47 separator(),
48 };
49 for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
50 children.push_back(text(keys[i].DebugString()));
51 }
52 return vbox(children);
53 });
54
55 int split_size = 40;
56 auto component = ResizableSplitLeft(left_column, right_column, &split_size);
58
59 component |= CatchEvent([&](Event event) {
60 keys.push_back(event);
61 return false;
62 });
63
64 screen.Loop(component);
65}
auto component
Definition gallery.cpp:127
static ScreenInteractive TerminalOutput()
const std::string & input() const
Definition event.hpp:102
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
Component ResizableSplitLeft(Component main, Component back, int *main_size)
兩個元件之間的水平分割,可透過滑鼠設定。
代表一個事件。它可以是按鍵事件、終端機大小調整,或更多...
Definition event.hpp:27
Element text(std::wstring text)
顯示一段 Unicode 文字。
Definition text.cpp:160
Element separator()
在兩個元素之間繪製垂直或水平分隔線。
Element border(Element)
在元素周圍繪製邊框。
Element vbox(Elements)
一個垂直一個接一個顯示元素的容器。
Definition vbox.cpp:95
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::vector< Element > Elements
Definition elements.hpp:23
Component CatchEvent(Component child, std::function< bool(Event)>)
std::string Code(Event event)
int main()