import { C0 } from './EscapeSequences';
import { IInputHandler } from './Interfaces';
-import { CHARSETS } from './Charsets';
+import { CHARSETS, DEFAULT_CHARSET } from './Charsets';
const normalStateHandler: {[key: string]: (parser: Parser, handler: IInputHandler) => void} = {};
normalStateHandler[C0.BEL] = (parser, handler) => handler.bell();
};
escapedStateHandler['E'] = (parser, terminal) => {
// ESC E Next Line ( NEL is 0x85).
- terminal.x = 0;
+ terminal.buffer.x = 0;
terminal.index();
parser.setState(ParserState.NORMAL);
};
// ESC % Select default/utf-8 character set.
// @ = default, G = utf-8
terminal.setgLevel(0);
- terminal.setgCharset(0, CHARSETS.US);
+ terminal.setgCharset(0, DEFAULT_CHARSET); // US (default)
parser.setState(ParserState.NORMAL);
parser.skipNextChar();
};
csiStateHandler['u'] = (handler, params) => handler.restoreCursor(params);
csiStateHandler[C0.CAN] = (handler, params, prefix, postfix, parser) => parser.setState(ParserState.NORMAL);
-// TODO: Many codes/charsets appear to not be supported
-// See: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
-const charsetMap = {
- '0': CHARSETS.SCLD,
- 'A': CHARSETS.UK, // United Kingdom
- 'B': CHARSETS.US, // United States (USASCII)
- '4': CHARSETS.Dutch,
- 'C': CHARSETS.Finnish,
- '5': CHARSETS.Finnish,
- 'f': CHARSETS.French,
- 'Q': CHARSETS.FrenchCanadian,
- 'K': CHARSETS.German,
- 'Y': CHARSETS.Italian,
- 'E': CHARSETS.NorwegianDanish,
- '6': CHARSETS.NorwegianDanish,
- 'Z': CHARSETS.Spanish,
- 'H': CHARSETS.Swedish,
- '7': CHARSETS.Swedish,
- '=': CHARSETS.Swiss,
- '/': CHARSETS.ISOLatin // ISOLatin is actually /A
-};
-
enum ParserState {
NORMAL = 0,
ESCAPED = 1,
*
* @param data The data to parse.
*/
- public parse(data: string) {
+ public parse(data: string): ParserState {
let l = data.length, j, cs, ch, code, low;
+ if (this._terminal.debug) {
+ this._terminal.log('data: ' + data);
+ }
+
this._position = 0;
// apply leftover surrogate high from last write
if (this._terminal.surrogate_high) {
break;
case ParserState.CHARSET:
- if (ch in charsetMap) {
- cs = charsetMap[ch];
+ if (ch in CHARSETS) {
+ cs = CHARSETS[ch];
if (ch === '/') { // ISOLatin is actually /A
this.skipNextChar();
}
} else {
- cs = CHARSETS.US; // Default
+ cs = DEFAULT_CHARSET;
}
this._terminal.setgCharset(this._terminal.gcharset, cs);
this._terminal.gcharset = null;
case ParserState.CSI:
if (ch in csiStateHandler) {
+ if (this._terminal.debug) {
+ this._terminal.log(`CSI ${this._terminal.prefix ? this._terminal.prefix : ''} ${this._terminal.params ? this._terminal.params.join(';') : ''} ${this._terminal.postfix ? this._terminal.postfix : ''} ${ch}`);
+ }
csiStateHandler[ch](this._inputHandler, this._terminal.params, this._terminal.prefix, this._terminal.postfix, this);
} else {
this._terminal.error('Unknown CSI code: %s.', ch);
case ParserState.DCS:
if (ch === C0.ESC || ch === C0.BEL) {
if (ch === C0.ESC) this._position++;
+ let pt;
+ let valid: boolean;
switch (this._terminal.prefix) {
// User-Defined Keys (DECUDK).
// Request Status String (DECRQSS).
// test: echo -e '\eP$q"p\e\\'
case '$q':
- let pt = this._terminal.currentParam
- , valid = false;
+ pt = this._terminal.currentParam;
+ valid = false;
switch (pt) {
// DECSCA
// DECSTBM
case 'r':
pt = ''
- + (this._terminal.scrollTop + 1)
+ + (this._terminal.buffer.scrollTop + 1)
+ ';'
- + (this._terminal.scrollBottom + 1)
+ + (this._terminal.buffer.scrollBottom + 1)
+ 'r';
break;
// This can cause a small glitch in vim.
// test: echo -ne '\eP+q6b64\e\\'
case '+q':
- // TODO: Don't declare pt twice
- /*let*/ pt = this._terminal.currentParam
- , valid = false;
+ pt = this._terminal.currentParam;
+ valid = false;
this._terminal.send(C0.ESC + 'P' + +valid + '+r' + pt + C0.ESC + '\\');
break;
break;
}
}
+ return this._state;
}
/**