FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
terminal_input_parser.hpp
浏览该文件的文档.
1// 版权所有 2020 Arthur Sonzogni。保留所有权利。
2// 本源代码的使用受 MIT 许可证的约束,该许可证可在
3// LICENSE 文件中找到。
4#ifndef FTXUI_COMPONENT_TERMINAL_INPUT_PARSER
5#define FTXUI_COMPONENT_TERMINAL_INPUT_PARSER
6
7#include <functional>
8#include <string> // for string
9#include <vector> // for vector
10
11#include "ftxui/component/mouse.hpp" // for Mouse
12
13namespace ftxui {
14struct Event;
15
16// 解析一段时间内的字符序列。生成事件。
18 public:
19 explicit TerminalInputParser(std::function<void(Event)> out);
20 void Timeout(int time);
21 void Add(char c);
22
23 private:
24 unsigned char Current();
25 bool Eat();
26
27 enum Type {
28 UNCOMPLETED,
29 DROP,
30 CHARACTER,
31 MOUSE,
32 CURSOR_POSITION,
33 CURSOR_SHAPE,
34 SPECIAL,
35 };
36
37 struct CursorPosition {
38 int x;
39 int y;
40 };
41
42 struct Output {
43 Type type;
44 union {
45 Mouse mouse;
46 CursorPosition cursor{};
47 int cursor_shape;
48 };
49
50 Output(Type t) // NOLINT
51 : type(t) {}
52 };
53
54 void Send(Output output);
55 Output Parse();
56 Output ParseUTF8();
57 Output ParseESC();
58 Output ParseDCS();
59 Output ParseCSI();
60 Output ParseOSC();
61 Output ParseMouse(bool altered, bool pressed, std::vector<int> arguments);
62 Output ParseCursorPosition(std::vector<int> arguments);
63
64 std::function<void(Event)> out_;
65 int position_ = -1;
66 int timeout_ = 0;
67 std::string pending_;
68};
69
70} // namespace ftxui
71
72#endif /* end of include guard: FTXUI_COMPONENT_TERMINAL_INPUT_PARSER */
TerminalInputParser(std::function< void(Event)> out)
代表一个事件。它可以是按键事件、终端大小调整等等...
一个鼠标事件。它包含鼠标的坐标、按下的按钮以及修饰符(shift、ctrl、meta)。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase