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,
39 FocusOut
40 };
41 Type type = None;
42 KeyEvent::Key key = KeyEvent::Key_Unknown;
43 uint8_t modifiers = 0;
44 String text;
45 // Mouse fields
46 Point2Di32 mousePos;
47 MouseEvent::Button mouseButton = MouseEvent::NoButton;
48 MouseEvent::Action mouseAction = MouseEvent::Press;
49 uint8_t mouseButtons = 0;
50 };
51
53
60 List<ParsedEvent> feed(const char *data, int len);
61
62 private:
63 enum State {
64 Normal,
65 EscapeStart,
66 CSI,
67 SS3,
68 CSIParam,
69 MouseSGR,
70 Paste
71 };
72
73 // Upper bound on a single bracketed-paste payload. Guards
74 // against an unterminated paste (missing ESC [ 201 ~) growing
75 // the buffer without bound or wedging the parser in Paste state.
76 static constexpr size_t kMaxPasteBytes = 8 * 1024 * 1024;
77
78 State _state = Normal;
79 String _buf;
80 String _pasteBuf;
81 uint8_t _buttonState = 0;
82
83 void parseCSI(const String &seq, List<ParsedEvent> &events);
84 void parseSS3(char ch, List<ParsedEvent> &events);
85 void parseMouseSGR(const String &seq, List<ParsedEvent> &events);
86 static KeyEvent::Key csiToKey(int code, int modifier);
87};
88
89PROMEKI_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
Type
Definition inputparser.h:33
@ Paste
Bracketed-paste content; payload in text.
Definition inputparser.h:37
@ FocusIn
Terminal window gained focus (mode 1004).
Definition inputparser.h:38