1/// This is the state change table. It's indexed first by current state and then by the next
2/// character in the pty stream.
3
4use definitions::Action;
5
6pub static STATE_CHANGE: [[u8; 256]; 16] = vt_state_table! {
7    State::Anywhere => {
8        0x18        => (Action::Execute, State::Ground),
9        0x1a        => (Action::Execute, State::Ground),
10        0x1b        => State::Escape,
11    },
12
13    State::Ground => {
14        0x00...0x17 => Action::Execute,
15        0x19        => Action::Execute,
16        0x1c...0x1f => Action::Execute,
17        0x20...0x7f => Action::Print,
18        0x80...0x8f => Action::Execute,
19        0x91...0x9a => Action::Execute,
20        0x9c        => Action::Execute,
21        // Beginning of UTF-8 2 byte sequence
22        0xc2...0xdf => (State::Utf8, Action::BeginUtf8),
23        // Beginning of UTF-8 3 byte sequence
24        0xe0...0xef => (State::Utf8, Action::BeginUtf8),
25        // Beginning of UTF-8 4 byte sequence
26        0xf0...0xf4 => (State::Utf8, Action::BeginUtf8),
27    },
28
29    State::Escape => {
30        0x00...0x17 => Action::Execute,
31        0x19        => Action::Execute,
32        0x1c...0x1f => Action::Execute,
33        0x7f        => Action::Ignore,
34        0x20...0x2f => (Action::Collect, State::EscapeIntermediate),
35        0x30...0x4f => (Action::EscDispatch, State::Ground),
36        0x51...0x57 => (Action::EscDispatch, State::Ground),
37        0x59        => (Action::EscDispatch, State::Ground),
38        0x5a        => (Action::EscDispatch, State::Ground),
39        0x5c        => (Action::EscDispatch, State::Ground),
40        0x60...0x7e => (Action::EscDispatch, State::Ground),
41        0x5b        => State::CsiEntry,
42        0x5d        => State::OscString,
43        0x50        => State::DcsEntry,
44        0x58        => State::SosPmApcString,
45        0x5e        => State::SosPmApcString,
46        0x5f        => State::SosPmApcString,
47    },
48
49    State::EscapeIntermediate => {
50        0x00...0x17 => Action::Execute,
51        0x19        => Action::Execute,
52        0x1c...0x1f => Action::Execute,
53        0x20...0x2f => Action::Collect,
54        0x7f        => Action::Ignore,
55        0x30...0x7e => (Action::EscDispatch, State::Ground)
56    },
57
58    State::CsiEntry => {
59        0x00...0x17 => Action::Execute,
60        0x19        => Action::Execute,
61        0x1c...0x1f => Action::Execute,
62        0x7f        => Action::Ignore,
63        0x20...0x2f => (Action::Collect, State::CsiIntermediate),
64        0x3a        => State::CsiIgnore,
65        0x30...0x39 => (Action::Param, State::CsiParam),
66        0x3b        => (Action::Param, State::CsiParam),
67        0x3c...0x3f => (Action::Collect, State::CsiParam),
68        0x40...0x7e => (Action::CsiDispatch, State::Ground)
69    },
70
71    State::CsiIgnore => {
72        0x00...0x17 => Action::Execute,
73        0x19        => Action::Execute,
74        0x1c...0x1f => Action::Execute,
75        0x20...0x3f => Action::Ignore,
76        0x7f        => Action::Ignore,
77        0x40...0x7e => State::Ground,
78    },
79
80    State::CsiParam => {
81        0x00...0x17 => Action::Execute,
82        0x19        => Action::Execute,
83        0x1c...0x1f => Action::Execute,
84        0x30...0x39 => Action::Param,
85        0x3b        => Action::Param,
86        0x7f        => Action::Ignore,
87        0x3a        => State::CsiIgnore,
88        0x3c...0x3f => State::CsiIgnore,
89        0x20...0x2f => (Action::Collect, State::CsiIntermediate),
90        0x40...0x7e => (Action::CsiDispatch, State::Ground)
91    },
92
93    State::CsiIntermediate => {
94        0x00...0x17 => Action::Execute,
95        0x19        => Action::Execute,
96        0x1c...0x1f => Action::Execute,
97        0x20...0x2f => Action::Collect,
98        0x7f        => Action::Ignore,
99        0x30...0x3f => State::CsiIgnore,
100        0x40...0x7e => (Action::CsiDispatch, State::Ground),
101    },
102
103    State::DcsEntry => {
104        0x00...0x17 => Action::Ignore,
105        0x19        => Action::Ignore,
106        0x1c...0x1f => Action::Ignore,
107        0x7f        => Action::Ignore,
108        0x3a        => State::DcsIgnore,
109        0x20...0x2f => (Action::Collect, State::DcsIntermediate),
110        0x30...0x39 => (Action::Param, State::DcsParam),
111        0x3b        => (Action::Param, State::DcsParam),
112        0x3c...0x3f => (Action::Collect, State::DcsParam),
113        0x40...0x7e => State::DcsPassthrough
114    },
115
116    State::DcsIntermediate => {
117        0x00...0x17 => Action::Ignore,
118        0x19        => Action::Ignore,
119        0x1c...0x1f => Action::Ignore,
120        0x20...0x2f => Action::Collect,
121        0x7f        => Action::Ignore,
122        0x30...0x3f => State::DcsIgnore,
123        0x40...0x7e => State::DcsPassthrough
124    },
125
126    State::DcsIgnore => {
127        0x00...0x17 => Action::Ignore,
128        0x19        => Action::Ignore,
129        0x1c...0x1f => Action::Ignore,
130        0x20...0x7f => Action::Ignore,
131        0x9c        => State::Ground
132    },
133
134    State::DcsParam => {
135        0x00...0x17 => Action::Ignore,
136        0x19        => Action::Ignore,
137        0x1c...0x1f => Action::Ignore,
138        0x30...0x39 => Action::Param,
139        0x3b        => Action::Param,
140        0x7f        => Action::Ignore,
141        0x3a        => State::DcsIgnore,
142        0x3c...0x3f => State::DcsIgnore,
143        0x20...0x2f => (Action::Collect, State::DcsIntermediate),
144        0x40...0x7e => State::DcsPassthrough
145    },
146
147    State::DcsPassthrough => {
148        0x00...0x17 => Action::Put,
149        0x19        => Action::Put,
150        0x1c...0x1f => Action::Put,
151        0x20...0x7e => Action::Put,
152        0x7f        => Action::Ignore,
153        0x9c        => State::Ground,
154    },
155
156    State::SosPmApcString => {
157        0x00...0x17 => Action::Ignore,
158        0x19        => Action::Ignore,
159        0x1c...0x1f => Action::Ignore,
160        0x20...0x7f => Action::Ignore,
161        0x9c       => State::Ground
162    },
163
164    State::OscString => {
165        0x00...0x06 => Action::Ignore,
166        0x07        => State::Ground,
167        0x08...0x17 => Action::Ignore,
168        0x19        => Action::Ignore,
169        0x1c...0x1f => Action::Ignore,
170        0x20...0xff => Action::OscPut,
171    }
172};
173
174pub static ENTRY_ACTIONS: &'static [Action] = &[
175   Action::None,     // State::Anywhere
176   Action::Clear,    // State::CsiEntry
177   Action::None,     // State::CsiIgnore
178   Action::None,     // State::CsiIntermediate
179   Action::None,     // State::CsiParam
180   Action::Clear,    // State::DcsEntry
181   Action::None,     // State::DcsIgnore
182   Action::None,     // State::DcsIntermediate
183   Action::None,     // State::DcsParam
184   Action::Hook,     // State::DcsPassthrough
185   Action::Clear,    // State::Escape
186   Action::None,     // State::EscapeIntermediate
187   Action::None,     // State::Ground
188   Action::OscStart, // State::OscString
189   Action::None,     // State::SosPmApcString
190   Action::None,     // State::Utf8
191];
192
193pub static EXIT_ACTIONS: &'static [Action] = &[
194   Action::None,   // State::Anywhere
195   Action::None,   // State::CsiEntry
196   Action::None,   // State::CsiIgnore
197   Action::None,   // State::CsiIntermediate
198   Action::None,   // State::CsiParam
199   Action::None,   // State::DcsEntry
200   Action::None,   // State::DcsIgnore
201   Action::None,   // State::DcsIntermediate
202   Action::None,   // State::DcsParam
203   Action::Unhook, // State::DcsPassthrough
204   Action::None,   // State::Escape
205   Action::None,   // State::EscapeIntermediate
206   Action::None,   // State::Ground
207   Action::OscEnd, // State::OscString
208   Action::None,   // State::SosPmApcString
209   Action::None,   // State::Utf8
210];
211