summaryrefslogtreecommitdiff
path: root/src/ui_terminal.h
blob: 266fc07020f06d66be72c07ee675e703adf0aba6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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;

    };

}