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