From c644379e79262a7478a7fb9ea8001f315fdb6eaf Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 28 Mar 2024 16:18:36 -0400 Subject: Initial commit --- src/ui_terminal.h | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/ui_terminal.h (limited to 'src/ui_terminal.h') diff --git a/src/ui_terminal.h b/src/ui_terminal.h new file mode 100644 index 0000000..266fc07 --- /dev/null +++ b/src/ui_terminal.h @@ -0,0 +1,102 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace ui { + + // Escape (ESC) and Control (CSI) commands. + enum commands { + // Specific to this codebase + INCOMPLETE, // We are in the middle of parsing a not-yet-completed command + NOTCOMMAND, // We are not currently parsing a command; the character is placed in callback args + INVALID, // Command was fully parsed but was invalid + // Control characters + BEL, + BS, + HT, + LF, + VT, + FF, + CR, + SO, + SI, + DEL, + // ESC commands + DECALN, + DECPAM, + DECPNM, + DECRC, + DECSC, + HTS, + IND, + NEL, + RI, + RIS, + SCSG0_OFF, + SCSG0_ON, + SCSG1_OFF, + SCSG1_ON, + ST, + // CSI commands + CBT, + CNL, + CPL, + CUB, + CUD, + CUF, + CHA, + CUP, + CUU, + DA, + DCH, + DECSTBM, + DL, + DSR, + ECH, + ED, + EL, + HPA, + HPR, + HVP, + ICH, + IL, + RCP, + REP, + RM, + RM_PRIVATE, + SCP, + SD, + SGR, + SM, + SM_PRIVATE, + SM_GRAPHICS, + SU, + TBC, + VPA, + VPR, + WINOPS + }; + + struct commandParserImpl; + + class CommandParser { + public: + // Construct a parser which does not automatically execute commands + CommandParser(); + // Construct a parser that calls a function when a command is parsed + CommandParser(std::map)>>); + ~CommandParser() {} + + // Parse the next character in the stream. This is stateful. + std::tuple> parse(int); + + + private: + std::shared_ptr data; + + }; + +} -- cgit v1.2.3