Handle remaining CSI_PARAM cases and introduce the state
This commit is contained in:
+18
-17
@@ -32,7 +32,7 @@ csiParamStateHandler['$'] = (parser) => parser.setPostfix('$');
|
|||||||
csiParamStateHandler['"'] = (parser) => parser.setPostfix('"');
|
csiParamStateHandler['"'] = (parser) => parser.setPostfix('"');
|
||||||
csiParamStateHandler[' '] = (parser) => parser.setPostfix(' ');
|
csiParamStateHandler[' '] = (parser) => parser.setPostfix(' ');
|
||||||
csiParamStateHandler['\''] = (parser) => parser.setPostfix('\'');
|
csiParamStateHandler['\''] = (parser) => parser.setPostfix('\'');
|
||||||
// TODO: Handle ';' and default (move on to ParserState.CSI (from CSI_PARAM)
|
csiParamStateHandler[';'] = (parser) => parser.finalizeParam();
|
||||||
|
|
||||||
const csiStateHandler: {[key: string]: (handler: IInputHandler, params: number[]) => void} = {};
|
const csiStateHandler: {[key: string]: (handler: IInputHandler, params: number[]) => void} = {};
|
||||||
csiStateHandler['A'] = (handler, params) => handler.cursorUp(params);
|
csiStateHandler['A'] = (handler, params) => handler.cursorUp(params);
|
||||||
@@ -43,11 +43,12 @@ csiStateHandler['D'] = (handler, params) => handler.cursorBackward(params);
|
|||||||
enum ParserState {
|
enum ParserState {
|
||||||
NORMAL = 0,
|
NORMAL = 0,
|
||||||
ESCAPED = 1,
|
ESCAPED = 1,
|
||||||
CSI = 2,
|
CSI_PARAM = 2,
|
||||||
OSC = 3,
|
CSI = 3,
|
||||||
CHARSET = 4,
|
OSC = 4,
|
||||||
DCS = 5,
|
CHARSET = 5,
|
||||||
IGNORE = 6
|
DCS = 6,
|
||||||
|
IGNORE = 7
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Parser {
|
export class Parser {
|
||||||
@@ -194,7 +195,7 @@ export class Parser {
|
|||||||
case '[':
|
case '[':
|
||||||
this._terminal.params = [];
|
this._terminal.params = [];
|
||||||
this._terminal.currentParam = 0;
|
this._terminal.currentParam = 0;
|
||||||
this.state = ParserState.CSI;
|
this.state = ParserState.CSI_PARAM;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// ESC ] Operating System Command ( OSC is 0x9d).
|
// ESC ] Operating System Command ( OSC is 0x9d).
|
||||||
@@ -513,21 +514,16 @@ export class Parser {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ParserState.CSI:
|
case ParserState.CSI_PARAM:
|
||||||
if (ch in csiParamStateHandler) {
|
if (ch in csiParamStateHandler) {
|
||||||
csiParamStateHandler[ch](this);
|
csiParamStateHandler[ch](this);
|
||||||
// Skip below switch as this has handled these codes (eventually everything will be handled here
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
this.finalizeParam();
|
||||||
|
// Fall through the CSI as this character should be the CSI code.
|
||||||
|
this.state = ParserState.CSI;
|
||||||
|
|
||||||
// TODO: a new state should be introduced? to differentiate checking for params and the codes
|
case ParserState.CSI:
|
||||||
|
|
||||||
this._terminal.params.push(this._terminal.currentParam);
|
|
||||||
this._terminal.currentParam = 0;
|
|
||||||
|
|
||||||
// ';'
|
|
||||||
if (ch === ';') break;
|
|
||||||
|
|
||||||
this.state = ParserState.NORMAL;
|
this.state = ParserState.NORMAL;
|
||||||
|
|
||||||
if (ch in csiStateHandler) {
|
if (ch in csiStateHandler) {
|
||||||
@@ -1048,6 +1044,11 @@ export class Parser {
|
|||||||
return this._terminal.currentParam;
|
return this._terminal.currentParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public finalizeParam(): void {
|
||||||
|
this._terminal.params.push(this._terminal.currentParam);
|
||||||
|
this._terminal.currentParam = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public setPostfix(postfix: string): void {
|
public setPostfix(postfix: string): void {
|
||||||
this._terminal.postfix = postfix;
|
this._terminal.postfix = postfix;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user