Some polish

This commit is contained in:
Daniel Imms
2018-05-05 08:12:52 -07:00
parent edb06c6b2a
commit 362d7698f7
5 changed files with 22 additions and 16 deletions
+2 -2
View File
@@ -119,13 +119,13 @@ parser.setOscHandlerFallback((...params: any[]) => {
if (params[0] === -1) testTerminal.actionOSC(params[1]); // handle error condition silently if (params[0] === -1) testTerminal.actionOSC(params[1]); // handle error condition silently
else testTerminal.actionOSC(params[0] + ';' + params[1]); else testTerminal.actionOSC(params[0] + ';' + params[1]);
}); });
parser.setDcsHandlerFallback(new DcsTest); parser.setDcsHandlerFallback(new DcsTest());
describe('EscapeSequenceParser', function (): void { describe('EscapeSequenceParser', function (): void {
describe('Parser init and methods', function (): void { describe('Parser init and methods', function (): void {
it('constructor', function(): void { it('constructor', function(): void {
let p: EscapeSequenceParser = new EscapeSequenceParser; let p: EscapeSequenceParser = new EscapeSequenceParser();
chai.expect(p.transitions).equal(VT500_TRANSITION_TABLE); chai.expect(p.transitions).equal(VT500_TRANSITION_TABLE);
p = new EscapeSequenceParser(VT500_TRANSITION_TABLE); p = new EscapeSequenceParser(VT500_TRANSITION_TABLE);
chai.expect(p.transitions).equal(VT500_TRANSITION_TABLE); chai.expect(p.transitions).equal(VT500_TRANSITION_TABLE);
+9 -12
View File
@@ -5,12 +5,16 @@
import { ParserState, ParserAction, IParsingState, IDcsHandler, IEscapeSequenceParser } from './Types'; import { ParserState, ParserAction, IParsingState, IDcsHandler, IEscapeSequenceParser } from './Types';
// number range macro /**
function r(a: number, b: number): number[] { * Returns an array fulled with numbers between the low and high parameters (inclusive).
let c = b - a; * @param low The low number.
* @param high The high number.
*/
function r(low: number, high: number): number[] {
let c = high - low;
let arr = new Array(c); let arr = new Array(c);
while (c--) { while (c--) {
arr[c] = --b; arr[c] = --high;
} }
return arr; return arr;
} }
@@ -243,7 +247,7 @@ export class EscapeSequenceParser implements IEscapeSequenceParser {
this._csiHandlerFb = (...params: any[]): void => { }; this._csiHandlerFb = (...params: any[]): void => { };
this._escHandlerFb = (...params: any[]): void => { }; this._escHandlerFb = (...params: any[]): void => { };
this._oscHandlerFb = (...params: any[]): void => { }; this._oscHandlerFb = (...params: any[]): void => { };
this._dcsHandlerFb = new DcsDummy; this._dcsHandlerFb = new DcsDummy();
this._errorHandlerFb = (state: IParsingState): IParsingState => state; this._errorHandlerFb = (state: IParsingState): IParsingState => state;
this._printHandler = this._printHandlerFb; this._printHandler = this._printHandlerFb;
this._executeHandlers = Object.create(null); this._executeHandlers = Object.create(null);
@@ -319,9 +323,6 @@ export class EscapeSequenceParser implements IEscapeSequenceParser {
this._errorHandler = this._errorHandlerFb; this._errorHandler = this._errorHandlerFb;
} }
/**
* Reset the parser.
*/
reset(): void { reset(): void {
this.currentState = this.initialState; this.currentState = this.initialState;
this._osc = ''; this._osc = '';
@@ -330,10 +331,6 @@ export class EscapeSequenceParser implements IEscapeSequenceParser {
this._activeDcsHandler = null; this._activeDcsHandler = null;
} }
/**
* Parse string `data`.
* @param data
*/
parse(data: string): void { parse(data: string): void {
let code = 0; let code = 0;
let transition = 0; let transition = 0;
+2 -2
View File
@@ -4,7 +4,7 @@
* @license MIT * @license MIT
*/ */
import { CharData, IInputHandler, IDcsHandler } from './Types'; import { CharData, IInputHandler, IDcsHandler, IEscapeSequenceParser } from './Types';
import { C0, C1 } from './EscapeSequences'; import { C0, C1 } from './EscapeSequences';
import { CHARSETS, DEFAULT_CHARSET } from './Charsets'; import { CHARSETS, DEFAULT_CHARSET } from './Charsets';
import { CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX } from './Buffer'; import { CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX } from './Buffer';
@@ -112,7 +112,7 @@ export class InputHandler implements IInputHandler {
constructor( constructor(
private _terminal: any, private _terminal: any,
private _parser: EscapeSequenceParser = new EscapeSequenceParser) private _parser: IEscapeSequenceParser = new EscapeSequenceParser())
{ {
this._surrogateHigh = ''; this._surrogateHigh = '';
+8
View File
@@ -467,7 +467,15 @@ export interface IDcsHandler {
* EscapeSequenceParser interface. * EscapeSequenceParser interface.
*/ */
export interface IEscapeSequenceParser { export interface IEscapeSequenceParser {
/**
* Reset the parser to its initial state (handlers are kept).
*/
reset(): void; reset(): void;
/**
* Parse string `data`.
* @param data The data to parse.
*/
parse(data: string): void; parse(data: string): void;
setPrintHandler(callback: (data: string, start: number, end: number) => void): void; setPrintHandler(callback: (data: string, start: number, end: number) => void): void;
+1
View File
@@ -31,6 +31,7 @@
"parameter" "parameter"
], ],
"eofline": true, "eofline": true,
"new-parens": true,
"no-duplicate-imports": true, "no-duplicate-imports": true,
"no-eval": true, "no-eval": true,
"no-internal-module": true, "no-internal-module": true,