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| accross |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 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)
Represent an event. It can be key press event, a terminal resize, or more ...
Definition event.hpp:29
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