FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
terminal_input_parser.hpp
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#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// Parse a sequence of |char| across |time|. Produces |Event|.
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 RESYNC,
31 CHARACTER,
32 MOUSE,
33 CURSOR_POSITION,
34 CURSOR_SHAPE,
35 TERMINAL_NAME_VERSION,
36 TERMINAL_EMULATOR,
37 TERMINAL_CAPABILITIES,
38 SPECIAL,
39 };
40
41 struct CursorPosition {
42 int x;
43 int y;
44 };
45
46 struct TerminalNameVersion {
47 std::string name;
48 int version;
49 };
50
51 struct TerminalEmulator {
52 std::string name;
53 std::string version;
54 };
55
56 struct TerminalCapabilities {
57 std::vector<int> capabilities;
58 };
59
60 struct Output {
61 Type type;
62 union {
63 Mouse mouse;
64 CursorPosition cursor{};
65 int cursor_shape;
66 int terminal_version;
67 };
68 std::string terminal_name;
69 std::string terminal_version_string;
70 std::vector<int> terminal_capabilities;
71
72 Output(Type t) // NOLINT
73 : type(t) {}
74 };
75
76 void Send(Output output);
77 Output Parse();
78 Output ParseUTF8();
79 Output ParseESC();
80 Output ParseDCS();
81 Output ParseCSI();
82 Output ParseOSC();
83 Output ParseMouse(bool altered, bool pressed, std::vector<int> arguments);
84 Output ParseCursorPosition(std::vector<int> arguments);
85 Output ParseDeviceAttributes(bool altered_greater,
86 bool altered_question,
87 std::vector<int> arguments);
88
89 std::function<void(Event)> out_;
90 int position_ = -1;
91 int timeout_ = 0;
92 std::string pending_;
93};
94
95} // namespace ftxui
96
97#endif /* end of include guard: FTXUI_COMPONENT_TERMINAL_INPUT_PARSER */
TerminalInputParser(std::function< void(Event)> out)
The FTXUI ftxui:: namespace.
Definition animation.hpp:11