diff options
author | Your Name <you@example.com> | 2024-03-28 16:18:36 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2024-03-28 16:18:36 -0400 |
commit | c644379e79262a7478a7fb9ea8001f315fdb6eaf (patch) | |
tree | d71b15e396ebca28b76f0b5fd1971dd352877e4e /src/ui_terminal.h | |
download | nerdhack-master.tar.gz nerdhack-master.tar.bz2 nerdhack-master.zip |
Diffstat (limited to 'src/ui_terminal.h')
-rw-r--r-- | src/ui_terminal.h | 102 |
1 files changed, 102 insertions, 0 deletions
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 <vector> +#include <map> +#include <tuple> +#include <functional> +#include <memory> + +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<commands, std::function<void(std::vector<int>)>>); + ~CommandParser() {} + + // Parse the next character in the stream. This is stateful. + std::tuple<commands, std::vector<int>> parse(int); + + + private: + std::shared_ptr<commandParserImpl> data; + + }; + +} |