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