]> git.proxmox.com Git - mirror_xterm.js.git/blame - src/Parser.ts
Declare pt and valid vars in correct spot
[mirror_xterm.js.git] / src / Parser.ts
CommitLineData
ef60e50e
DI
1/**
2 * @license MIT
3 */
4
659fb90c
DI
5import { C0 } from './EscapeSequences';
6import { IInputHandler } from './Interfaces';
aab67c2e 7import { CHARSETS, DEFAULT_CHARSET } from './Charsets';
659fb90c 8
fa3484cd
DI
9const normalStateHandler: {[key: string]: (parser: Parser, handler: IInputHandler) => void} = {};
10normalStateHandler[C0.BEL] = (parser, handler) => handler.bell();
11normalStateHandler[C0.LF] = (parser, handler) => handler.lineFeed();
659fb90c
DI
12normalStateHandler[C0.VT] = normalStateHandler[C0.LF];
13normalStateHandler[C0.FF] = normalStateHandler[C0.LF];
fa3484cd
DI
14normalStateHandler[C0.CR] = (parser, handler) => handler.carriageReturn();
15normalStateHandler[C0.BS] = (parser, handler) => handler.backspace();
16normalStateHandler[C0.HT] = (parser, handler) => handler.tab();
17normalStateHandler[C0.SO] = (parser, handler) => handler.shiftOut();
18normalStateHandler[C0.SI] = (parser, handler) => handler.shiftIn();
19normalStateHandler[C0.ESC] = (parser, handler) => parser.setState(ParserState.ESCAPED);
672dc1a2 20
ecd7e69f
DI
21// TODO: Remove terminal when parser owns params and currentParam
22const escapedStateHandler: {[key: string]: (parser: Parser, terminal: any) => void} = {};
23escapedStateHandler['['] = (parser, terminal) => {
24 // ESC [ Control Sequence Introducer (CSI is 0x9b)
25 terminal.params = [];
26 terminal.currentParam = 0;
27 parser.setState(ParserState.CSI_PARAM);
28};
29escapedStateHandler[']'] = (parser, terminal) => {
30 // ESC ] Operating System Command (OSC is 0x9d)
31 terminal.params = [];
32 terminal.currentParam = 0;
33 parser.setState(ParserState.OSC);
34};
35escapedStateHandler['P'] = (parser, terminal) => {
36 // ESC P Device Control String (DCS is 0x90)
37 terminal.params = [];
38 terminal.currentParam = 0;
39 parser.setState(ParserState.DCS);
40};
41escapedStateHandler['_'] = (parser, terminal) => {
42 // ESC _ Application Program Command ( APC is 0x9f).
43 parser.setState(ParserState.IGNORE);
4448ebe3 44};
ecd7e69f
DI
45escapedStateHandler['^'] = (parser, terminal) => {
46 // ESC ^ Privacy Message ( PM is 0x9e).
47 parser.setState(ParserState.IGNORE);
4448ebe3 48};
ecd7e69f
DI
49escapedStateHandler['c'] = (parser, terminal) => {
50 // ESC c Full Reset (RIS).
51 terminal.reset();
4448ebe3 52};
ecd7e69f
DI
53escapedStateHandler['E'] = (parser, terminal) => {
54 // ESC E Next Line ( NEL is 0x85).
55 terminal.x = 0;
56 terminal.index();
57 parser.setState(ParserState.NORMAL);
4448ebe3 58};
ecd7e69f
DI
59escapedStateHandler['D'] = (parser, terminal) => {
60 // ESC D Index ( IND is 0x84).
61 terminal.index();
62 parser.setState(ParserState.NORMAL);
63};
64escapedStateHandler['M'] = (parser, terminal) => {
65 // ESC M Reverse Index ( RI is 0x8d).
66 terminal.reverseIndex();
67 parser.setState(ParserState.NORMAL);
68};
69escapedStateHandler['%'] = (parser, terminal) => {
70 // ESC % Select default/utf-8 character set.
71 // @ = default, G = utf-8
72 terminal.setgLevel(0);
aab67c2e 73 terminal.setgCharset(0, DEFAULT_CHARSET); // US (default)
ecd7e69f
DI
74 parser.setState(ParserState.NORMAL);
75 parser.skipNextChar();
76};
1b344ce7 77escapedStateHandler[C0.CAN] = (parser) => parser.setState(ParserState.NORMAL);
ecd7e69f 78
7572dd5f
DI
79const csiParamStateHandler: {[key: string]: (parser: Parser) => void} = {};
80csiParamStateHandler['?'] = (parser) => parser.setPrefix('?');
81csiParamStateHandler['>'] = (parser) => parser.setPrefix('>');
82csiParamStateHandler['!'] = (parser) => parser.setPrefix('!');
83csiParamStateHandler['0'] = (parser) => parser.setParam(parser.getParam() * 10);
84csiParamStateHandler['1'] = (parser) => parser.setParam(parser.getParam() * 10 + 1);
85csiParamStateHandler['2'] = (parser) => parser.setParam(parser.getParam() * 10 + 2);
86csiParamStateHandler['3'] = (parser) => parser.setParam(parser.getParam() * 10 + 3);
87csiParamStateHandler['4'] = (parser) => parser.setParam(parser.getParam() * 10 + 4);
88csiParamStateHandler['5'] = (parser) => parser.setParam(parser.getParam() * 10 + 5);
89csiParamStateHandler['6'] = (parser) => parser.setParam(parser.getParam() * 10 + 6);
90csiParamStateHandler['7'] = (parser) => parser.setParam(parser.getParam() * 10 + 7);
91csiParamStateHandler['8'] = (parser) => parser.setParam(parser.getParam() * 10 + 8);
92csiParamStateHandler['9'] = (parser) => parser.setParam(parser.getParam() * 10 + 9);
93csiParamStateHandler['$'] = (parser) => parser.setPostfix('$');
94csiParamStateHandler['"'] = (parser) => parser.setPostfix('"');
95csiParamStateHandler[' '] = (parser) => parser.setPostfix(' ');
96csiParamStateHandler['\''] = (parser) => parser.setPostfix('\'');
c7fa2d55 97csiParamStateHandler[';'] = (parser) => parser.finalizeParam();
1b344ce7 98csiParamStateHandler[C0.CAN] = (parser) => parser.setState(ParserState.NORMAL);
9942477b 99
1b344ce7 100const csiStateHandler: {[key: string]: (handler: IInputHandler, params: number[], prefix: string, postfix: string, parser: Parser) => void} = {};
f4846aa1
DI
101csiStateHandler['@'] = (handler, params, prefix) => handler.insertChars(params);
102csiStateHandler['A'] = (handler, params, prefix) => handler.cursorUp(params);
103csiStateHandler['B'] = (handler, params, prefix) => handler.cursorDown(params);
104csiStateHandler['C'] = (handler, params, prefix) => handler.cursorForward(params);
105csiStateHandler['D'] = (handler, params, prefix) => handler.cursorBackward(params);
106csiStateHandler['E'] = (handler, params, prefix) => handler.cursorNextLine(params);
107csiStateHandler['F'] = (handler, params, prefix) => handler.cursorPrecedingLine(params);
108csiStateHandler['G'] = (handler, params, prefix) => handler.cursorCharAbsolute(params);
109csiStateHandler['H'] = (handler, params, prefix) => handler.cursorPosition(params);
110csiStateHandler['I'] = (handler, params, prefix) => handler.cursorForwardTab(params);
111csiStateHandler['J'] = (handler, params, prefix) => handler.eraseInDisplay(params);
112csiStateHandler['K'] = (handler, params, prefix) => handler.eraseInLine(params);
113csiStateHandler['L'] = (handler, params, prefix) => handler.insertLines(params);
114csiStateHandler['M'] = (handler, params, prefix) => handler.deleteLines(params);
115csiStateHandler['P'] = (handler, params, prefix) => handler.deleteChars(params);
116csiStateHandler['S'] = (handler, params, prefix) => handler.scrollUp(params);
117csiStateHandler['T'] = (handler, params, prefix) => {
118 if (params.length < 2 && !prefix) {
119 handler.scrollDown(params);
120 }
121};
122csiStateHandler['X'] = (handler, params, prefix) => handler.eraseChars(params);
123csiStateHandler['Z'] = (handler, params, prefix) => handler.cursorBackwardTab(params);
124csiStateHandler['`'] = (handler, params, prefix) => handler.charPosAbsolute(params);
125csiStateHandler['a'] = (handler, params, prefix) => handler.HPositionRelative(params);
126csiStateHandler['b'] = (handler, params, prefix) => handler.repeatPrecedingCharacter(params);
127csiStateHandler['c'] = (handler, params, prefix) => handler.sendDeviceAttributes(params);
128csiStateHandler['d'] = (handler, params, prefix) => handler.linePosAbsolute(params);
129csiStateHandler['e'] = (handler, params, prefix) => handler.VPositionRelative(params);
130csiStateHandler['f'] = (handler, params, prefix) => handler.HVPosition(params);
131csiStateHandler['g'] = (handler, params, prefix) => handler.tabClear(params);
132csiStateHandler['h'] = (handler, params, prefix) => handler.setMode(params);
133csiStateHandler['l'] = (handler, params, prefix) => handler.resetMode(params);
134csiStateHandler['m'] = (handler, params, prefix) => handler.charAttributes(params);
135csiStateHandler['n'] = (handler, params, prefix) => handler.deviceStatus(params);
136csiStateHandler['p'] = (handler, params, prefix) => {
137 switch (prefix) {
138 case '!': handler.softReset(params); break;
139 }
140};
0bd469f5
DI
141csiStateHandler['q'] = (handler, params, prefix, postfix) => {
142 if (postfix === ' ') {
143 handler.setCursorStyle(params);
144 }
145};
9b662080
DI
146csiStateHandler['r'] = (handler, params) => handler.setScrollRegion(params);
147csiStateHandler['s'] = (handler, params) => handler.saveCursor(params);
148csiStateHandler['u'] = (handler, params) => handler.restoreCursor(params);
1b344ce7 149csiStateHandler[C0.CAN] = (handler, params, prefix, postfix, parser) => parser.setState(ParserState.NORMAL);
a31921ae
DI
150
151enum ParserState {
152 NORMAL = 0,
153 ESCAPED = 1,
c7fa2d55
DI
154 CSI_PARAM = 2,
155 CSI = 3,
156 OSC = 4,
157 CHARSET = 5,
158 DCS = 6,
159 IGNORE = 7
a31921ae
DI
160}
161
ef60e50e
DI
162/**
163 * The terminal's parser, all input into the terminal goes through the parser
164 * which parses and defers the actual input handling the the IInputHandler
165 * specified in the constructor.
166 */
a31921ae 167export class Parser {
ecd7e69f
DI
168 private _state: ParserState;
169 private _position: number;
a31921ae
DI
170
171 // TODO: Remove terminal when handler can do everything
172 constructor(
173 private _inputHandler: IInputHandler,
174 private _terminal: any
175 ) {
ecd7e69f 176 this._state = ParserState.NORMAL;
a31921ae
DI
177 }
178
ef60e50e
DI
179 /**
180 * Parse and handle data.
181 *
182 * @param data The data to parse.
183 */
a31921ae 184 public parse(data: string) {
ecd7e69f 185 let l = data.length, j, cs, ch, code, low;
a31921ae 186
ecd7e69f 187 this._position = 0;
a31921ae
DI
188 // apply leftover surrogate high from last write
189 if (this._terminal.surrogate_high) {
190 data = this._terminal.surrogate_high + data;
191 this._terminal.surrogate_high = '';
192 }
193
ecd7e69f
DI
194 for (; this._position < l; this._position++) {
195 ch = data[this._position];
a31921ae
DI
196
197 // FIXME: higher chars than 0xa0 are not allowed in escape sequences
198 // --> maybe move to default
ecd7e69f 199 code = data.charCodeAt(this._position);
a31921ae
DI
200 if (0xD800 <= code && code <= 0xDBFF) {
201 // we got a surrogate high
202 // get surrogate low (next 2 bytes)
ecd7e69f 203 low = data.charCodeAt(this._position + 1);
a31921ae
DI
204 if (isNaN(low)) {
205 // end of data stream, save surrogate high
206 this._terminal.surrogate_high = ch;
207 continue;
208 }
209 code = ((code - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
ecd7e69f 210 ch += data.charAt(this._position + 1);
a31921ae
DI
211 }
212 // surrogate low - already handled above
213 if (0xDC00 <= code && code <= 0xDFFF)
214 continue;
215
ecd7e69f 216 switch (this._state) {
a31921ae 217 case ParserState.NORMAL:
fa3484cd
DI
218 if (ch in normalStateHandler) {
219 normalStateHandler[ch](this, this._inputHandler);
220 } else {
221 this._inputHandler.addChar(ch, code);
a31921ae
DI
222 }
223 break;
224 case ParserState.ESCAPED:
ecd7e69f
DI
225 if (ch in escapedStateHandler) {
226 escapedStateHandler[ch](this, this._terminal);
227 // Skip switch as it was just handled
228 break;
229 }
a31921ae 230 switch (ch) {
a31921ae
DI
231
232 // ESC (,),*,+,-,. Designate G0-G2 Character Set.
233 case '(': // <-- this seems to get all the attention
234 case ')':
235 case '*':
236 case '+':
237 case '-':
238 case '.':
239 switch (ch) {
240 case '(':
991b2843 241 this._terminal.gcharset = 0;
a31921ae
DI
242 break;
243 case ')':
991b2843 244 this._terminal.gcharset = 1;
a31921ae
DI
245 break;
246 case '*':
991b2843 247 this._terminal.gcharset = 2;
a31921ae
DI
248 break;
249 case '+':
991b2843 250 this._terminal.gcharset = 3;
a31921ae
DI
251 break;
252 case '-':
991b2843 253 this._terminal.gcharset = 1;
a31921ae
DI
254 break;
255 case '.':
991b2843 256 this._terminal.gcharset = 2;
a31921ae
DI
257 break;
258 }
ecd7e69f 259 this._state = ParserState.CHARSET;
a31921ae
DI
260 break;
261
262 // Designate G3 Character Set (VT300).
263 // A = ISO Latin-1 Supplemental.
264 // Not implemented.
265 case '/':
991b2843 266 this._terminal.gcharset = 3;
ecd7e69f
DI
267 this._state = ParserState.CHARSET;
268 this._position--;
a31921ae
DI
269 break;
270
271 // ESC N
272 // Single Shift Select of G2 Character Set
273 // ( SS2 is 0x8e). This affects next character only.
274 case 'N':
275 break;
276 // ESC O
277 // Single Shift Select of G3 Character Set
278 // ( SS3 is 0x8f). This affects next character only.
279 case 'O':
280 break;
281 // ESC n
282 // Invoke the G2 Character Set as GL (LS2).
283 case 'n':
991b2843 284 this._terminal.setgLevel(2);
a31921ae
DI
285 break;
286 // ESC o
287 // Invoke the G3 Character Set as GL (LS3).
288 case 'o':
991b2843 289 this._terminal.setgLevel(3);
a31921ae
DI
290 break;
291 // ESC |
292 // Invoke the G3 Character Set as GR (LS3R).
293 case '|':
991b2843 294 this._terminal.setgLevel(3);
a31921ae
DI
295 break;
296 // ESC }
297 // Invoke the G2 Character Set as GR (LS2R).
298 case '}':
991b2843 299 this._terminal.setgLevel(2);
a31921ae
DI
300 break;
301 // ESC ~
302 // Invoke the G1 Character Set as GR (LS1R).
303 case '~':
991b2843 304 this._terminal.setgLevel(1);
a31921ae
DI
305 break;
306
307 // ESC 7 Save Cursor (DECSC).
308 case '7':
f4846aa1 309 this._inputHandler.saveCursor();
ecd7e69f 310 this._state = ParserState.NORMAL;
a31921ae
DI
311 break;
312
313 // ESC 8 Restore Cursor (DECRC).
314 case '8':
f4846aa1 315 this._inputHandler.restoreCursor();
ecd7e69f 316 this._state = ParserState.NORMAL;
a31921ae
DI
317 break;
318
319 // ESC # 3 DEC line height/width
320 case '#':
ecd7e69f
DI
321 this._state = ParserState.NORMAL;
322 this._position++;
a31921ae
DI
323 break;
324
325 // ESC H Tab Set (HTS is 0x88).
326 case 'H':
991b2843 327 this._terminal.tabSet();
ecd7e69f 328 this._state = ParserState.NORMAL;
a31921ae
DI
329 break;
330
331 // ESC = Application Keypad (DECKPAM).
332 case '=':
991b2843
DI
333 this._terminal.log('Serial port requested application keypad.');
334 this._terminal.applicationKeypad = true;
335 this._terminal.viewport.syncScrollArea();
ecd7e69f 336 this._state = ParserState.NORMAL;
a31921ae
DI
337 break;
338
339 // ESC > Normal Keypad (DECKPNM).
340 case '>':
991b2843
DI
341 this._terminal.log('Switching back to normal keypad.');
342 this._terminal.applicationKeypad = false;
343 this._terminal.viewport.syncScrollArea();
ecd7e69f 344 this._state = ParserState.NORMAL;
a31921ae
DI
345 break;
346
347 default:
ecd7e69f 348 this._state = ParserState.NORMAL;
991b2843 349 this._terminal.error('Unknown ESC control: %s.', ch);
a31921ae
DI
350 break;
351 }
352 break;
353
354 case ParserState.CHARSET:
aab67c2e
DI
355 if (ch in CHARSETS) {
356 cs = CHARSETS[ch];
4448ebe3
DI
357 if (ch === '/') { // ISOLatin is actually /A
358 this.skipNextChar();
359 }
360 } else {
aab67c2e 361 cs = DEFAULT_CHARSET;
a31921ae 362 }
991b2843
DI
363 this._terminal.setgCharset(this._terminal.gcharset, cs);
364 this._terminal.gcharset = null;
ecd7e69f 365 this._state = ParserState.NORMAL;
a31921ae
DI
366 break;
367
368 case ParserState.OSC:
369 // OSC Ps ; Pt ST
370 // OSC Ps ; Pt BEL
371 // Set Text Parameters.
372 if (ch === C0.ESC || ch === C0.BEL) {
ecd7e69f 373 if (ch === C0.ESC) this._position++;
a31921ae 374
991b2843 375 this._terminal.params.push(this._terminal.currentParam);
a31921ae 376
991b2843 377 switch (this._terminal.params[0]) {
a31921ae
DI
378 case 0:
379 case 1:
380 case 2:
991b2843
DI
381 if (this._terminal.params[1]) {
382 this._terminal.title = this._terminal.params[1];
383 this._terminal.handleTitle(this._terminal.title);
a31921ae
DI
384 }
385 break;
386 case 3:
387 // set X property
388 break;
389 case 4:
390 case 5:
391 // change dynamic colors
392 break;
393 case 10:
394 case 11:
395 case 12:
396 case 13:
397 case 14:
398 case 15:
399 case 16:
400 case 17:
401 case 18:
402 case 19:
403 // change dynamic ui colors
404 break;
405 case 46:
406 // change log file
407 break;
408 case 50:
409 // dynamic font
410 break;
411 case 51:
412 // emacs shell
413 break;
414 case 52:
415 // manipulate selection data
416 break;
417 case 104:
418 case 105:
419 case 110:
420 case 111:
421 case 112:
422 case 113:
423 case 114:
424 case 115:
425 case 116:
426 case 117:
427 case 118:
428 // reset colors
429 break;
430 }
431
991b2843
DI
432 this._terminal.params = [];
433 this._terminal.currentParam = 0;
ecd7e69f 434 this._state = ParserState.NORMAL;
a31921ae 435 } else {
991b2843 436 if (!this._terminal.params.length) {
a31921ae 437 if (ch >= '0' && ch <= '9') {
991b2843
DI
438 this._terminal.currentParam =
439 this._terminal.currentParam * 10 + ch.charCodeAt(0) - 48;
a31921ae 440 } else if (ch === ';') {
991b2843
DI
441 this._terminal.params.push(this._terminal.currentParam);
442 this._terminal.currentParam = '';
a31921ae
DI
443 }
444 } else {
991b2843 445 this._terminal.currentParam += ch;
a31921ae
DI
446 }
447 }
448 break;
449
c7fa2d55 450 case ParserState.CSI_PARAM:
9942477b 451 if (ch in csiParamStateHandler) {
7572dd5f 452 csiParamStateHandler[ch](this);
a31921ae
DI
453 break;
454 }
c7fa2d55
DI
455 this.finalizeParam();
456 // Fall through the CSI as this character should be the CSI code.
ecd7e69f 457 this._state = ParserState.CSI;
a31921ae 458
c7fa2d55 459 case ParserState.CSI:
9942477b 460 if (ch in csiStateHandler) {
1b344ce7 461 csiStateHandler[ch](this._inputHandler, this._terminal.params, this._terminal.prefix, this._terminal.postfix, this);
f4846aa1
DI
462 } else {
463 this._terminal.error('Unknown CSI code: %s.', ch);
a31921ae
DI
464 }
465
ecd7e69f 466 this._state = ParserState.NORMAL;
991b2843
DI
467 this._terminal.prefix = '';
468 this._terminal.postfix = '';
a31921ae
DI
469 break;
470
471 case ParserState.DCS:
472 if (ch === C0.ESC || ch === C0.BEL) {
ecd7e69f 473 if (ch === C0.ESC) this._position++;
13088f55
DI
474 let pt;
475 let valid: boolean;
a31921ae 476
991b2843 477 switch (this._terminal.prefix) {
a31921ae
DI
478 // User-Defined Keys (DECUDK).
479 case '':
480 break;
481
482 // Request Status String (DECRQSS).
483 // test: echo -e '\eP$q"p\e\\'
484 case '$q':
13088f55
DI
485 pt = this._terminal.currentParam
486 valid = false;
a31921ae
DI
487
488 switch (pt) {
489 // DECSCA
490 case '"q':
491 pt = '0"q';
492 break;
493
494 // DECSCL
495 case '"p':
496 pt = '61"p';
497 break;
498
499 // DECSTBM
500 case 'r':
501 pt = ''
991b2843 502 + (this._terminal.scrollTop + 1)
a31921ae 503 + ';'
991b2843 504 + (this._terminal.scrollBottom + 1)
a31921ae
DI
505 + 'r';
506 break;
507
508 // SGR
509 case 'm':
510 pt = '0m';
511 break;
512
513 default:
991b2843 514 this._terminal.error('Unknown DCS Pt: %s.', pt);
a31921ae
DI
515 pt = '';
516 break;
517 }
518
991b2843 519 this._terminal.send(C0.ESC + 'P' + +valid + '$r' + pt + C0.ESC + '\\');
a31921ae
DI
520 break;
521
522 // Set Termcap/Terminfo Data (xterm, experimental).
523 case '+p':
524 break;
525
526 // Request Termcap/Terminfo String (xterm, experimental)
527 // Regular xterm does not even respond to this sequence.
528 // This can cause a small glitch in vim.
529 // test: echo -ne '\eP+q6b64\e\\'
530 case '+q':
13088f55
DI
531 pt = this._terminal.currentParam
532 valid = false;
a31921ae 533
991b2843 534 this._terminal.send(C0.ESC + 'P' + +valid + '+r' + pt + C0.ESC + '\\');
a31921ae
DI
535 break;
536
537 default:
991b2843 538 this._terminal.error('Unknown DCS prefix: %s.', this._terminal.prefix);
a31921ae
DI
539 break;
540 }
541
991b2843
DI
542 this._terminal.currentParam = 0;
543 this._terminal.prefix = '';
ecd7e69f 544 this._state = ParserState.NORMAL;
991b2843
DI
545 } else if (!this._terminal.currentParam) {
546 if (!this._terminal.prefix && ch !== '$' && ch !== '+') {
547 this._terminal.currentParam = ch;
548 } else if (this._terminal.prefix.length === 2) {
549 this._terminal.currentParam = ch;
a31921ae 550 } else {
991b2843 551 this._terminal.prefix += ch;
a31921ae
DI
552 }
553 } else {
991b2843 554 this._terminal.currentParam += ch;
a31921ae
DI
555 }
556 break;
557
558 case ParserState.IGNORE:
559 // For PM and APC.
560 if (ch === C0.ESC || ch === C0.BEL) {
ecd7e69f
DI
561 if (ch === C0.ESC) this._position++;
562 this._state = ParserState.NORMAL;
a31921ae
DI
563 }
564 break;
565 }
566 }
567 }
672dc1a2 568
ef60e50e
DI
569 /**
570 * Set the parser's current parsing state.
571 *
572 * @param state The new state.
573 */
fa3484cd 574 public setState(state: ParserState): void {
ecd7e69f 575 this._state = state;
fa3484cd
DI
576 }
577
ef60e50e
DI
578 /**
579 * Sets the parsier's current prefix. CSI codes can have prefixes of '?', '>'
580 * or '!'.
581 *
582 * @param prefix The prefix.
583 */
635a4d76 584 public setPrefix(prefix: string): void {
672dc1a2
DI
585 this._terminal.prefix = prefix;
586 }
587
ef60e50e
DI
588 /**
589 * Sets the parsier's current prefix. CSI codes can have postfixes of '$',
590 * '"', ' ', '\''.
591 *
592 * @param postfix The postfix.
593 */
594 public setPostfix(postfix: string): void {
595 this._terminal.postfix = postfix;
596 }
597
598 /**
599 * Sets the parser's current parameter.
600 *
601 * @param param the parameter.
602 */
672dc1a2
DI
603 public setParam(param: number) {
604 this._terminal.currentParam = param;
605 }
606
ef60e50e
DI
607 /**
608 * Gets the parser's current parameter.
609 */
672dc1a2
DI
610 public getParam(): number {
611 return this._terminal.currentParam;
612 }
635a4d76 613
ef60e50e
DI
614 /**
615 * Finalizes the parser's current parameter, adding it to the list of
616 * parameters and setting the new current parameter to 0.
617 */
c7fa2d55
DI
618 public finalizeParam(): void {
619 this._terminal.params.push(this._terminal.currentParam);
620 this._terminal.currentParam = 0;
621 }
622
ef60e50e
DI
623 /**
624 * Tell the parser to skip the next character.
625 */
ecd7e69f
DI
626 public skipNextChar(): void {
627 this._position++;
628 }
629
ef60e50e
DI
630 /**
631 * Tell the parser to repeat parsing the current character (for example if it
632 * needs parsing using a different state.
633 */
ecd7e69f
DI
634 // public repeatChar(): void {
635 // this._position--;
636 // }
a31921ae 637}