FTXUI  5.0.0
C++ functional terminal UI.
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 <memory> // for unique_ptr
8#include <string> // for string
9#include <vector> // for vector
10
11#include "ftxui/component/event.hpp" // for Event (ptr only)
12#include "ftxui/component/mouse.hpp" // for Mouse
13#include "ftxui/component/receiver.hpp" // for Sender
14#include "ftxui/component/task.hpp" // for Task
15
16namespace ftxui {
17struct Event;
18
19// Parse a sequence of |char| accross |time|. Produces |Event|.
21 public:
23 void Timeout(int time);
24 void Add(char c);
25
26 private:
27 unsigned char Current();
28 bool Eat();
29
30 enum Type {
31 UNCOMPLETED,
32 DROP,
33 CHARACTER,
34 MOUSE,
35 CURSOR_POSITION,
36 CURSOR_SHAPE,
37 SPECIAL,
38 };
39
40 struct CursorPosition {
41 int x;
42 int y;
43 };
44
45 struct Output {
46 Type type;
47 union {
48 Mouse mouse;
49 CursorPosition cursor;
50 int cursor_shape;
51 };
52
53 Output(Type t) : type(t) {}
54 };
55
56 void Send(Output output);
57 Output Parse();
58 Output ParseUTF8();
59 Output ParseESC();
60 Output ParseDCS();
61 Output ParseCSI();
62 Output ParseOSC();
63 Output ParseMouse(bool altered, bool pressed, std::vector<int> arguments);
64 Output ParseCursorPosition(std::vector<int> arguments);
65
66 Sender<Task> out_;
67 int position_ = -1;
68 int timeout_ = 0;
69 std::string pending_;
70};
71
72} // namespace ftxui
73
74#endif /* end of include guard: FTXUI_COMPONENT_TERMINAL_INPUT_PARSER */
TerminalInputParser(Sender< Task > out)
std::unique_ptr< SenderImpl< T > > Sender
Definition: receiver.hpp:47
A mouse event. It contains the coordinate of the mouse, the button pressed and the modifier (shift,...
Definition: mouse.hpp:11