libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
inputparser.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <promeki/namespace.h>
11#include <promeki/list.h>
12#include <promeki/keyevent.h>
13#include <promeki/mouseevent.h>
14
15PROMEKI_NAMESPACE_BEGIN
16
30 public:
32 struct ParsedEvent {
33 enum Type {
34 None,
35 Key,
36 Mouse
37 };
38 Type type = None;
39 KeyEvent::Key key = KeyEvent::Key_Unknown;
40 uint8_t modifiers = 0;
41 String text;
42 // Mouse fields
43 Point2Di32 mousePos;
44 MouseEvent::Button mouseButton = MouseEvent::NoButton;
45 MouseEvent::Action mouseAction = MouseEvent::Press;
46 uint8_t mouseButtons = 0;
47 };
48
50
57 List<ParsedEvent> feed(const char *data, int len);
58
59 private:
60 enum State {
61 Normal,
62 EscapeStart,
63 CSI,
64 SS3,
65 CSIParam,
66 MouseSGR
67 };
68
69 State _state = Normal;
70 String _buf;
71 uint8_t _buttonState = 0;
72
73 void parseCSI(const String &seq, List<ParsedEvent> &events);
74 void parseSS3(char ch, List<ParsedEvent> &events);
75 void parseMouseSGR(const String &seq, List<ParsedEvent> &events);
76 static KeyEvent::Key csiToKey(int code, int modifier);
77};
78
79PROMEKI_NAMESPACE_END
State machine for parsing terminal escape sequences into events.
Definition inputparser.h:29
List< ParsedEvent > feed(const char *data, int len)
Feeds raw input bytes into the parser.
Parsed event variant.
Definition inputparser.h:32