rename handler type aliases to XyType to avoid ambiguity with class based types

This commit is contained in:
Jörg Breitbart
2019-08-11 18:45:34 +02:00
parent 3a5d0bd368
commit a2c266a005
5 changed files with 56 additions and 56 deletions
+3 -3
View File
@@ -4,7 +4,7 @@
*/ */
import { IDisposable } from 'common/Types'; import { IDisposable } from 'common/Types';
import { IDcsHandler, IParams, IHandlerCollection, IDcsParser, DcsFallbackHandler } from 'common/parser/Types'; import { IDcsHandler, IParams, IHandlerCollection, IDcsParser, DcsFallbackHandlerType } from 'common/parser/Types';
import { utf32ToString } from 'common/input/TextDecoder'; import { utf32ToString } from 'common/input/TextDecoder';
import { Params } from 'common/parser/Params'; import { Params } from 'common/parser/Params';
import { PAYLOAD_LIMIT } from 'common/parser/Constants'; import { PAYLOAD_LIMIT } from 'common/parser/Constants';
@@ -15,7 +15,7 @@ export class DcsParser implements IDcsParser {
private _handlers: IHandlerCollection<IDcsHandler> = Object.create(null); private _handlers: IHandlerCollection<IDcsHandler> = Object.create(null);
private _active: IDcsHandler[] = EMPTY_HANDLERS; private _active: IDcsHandler[] = EMPTY_HANDLERS;
private _ident: number = 0; private _ident: number = 0;
private _handlerFb: DcsFallbackHandler = () => {}; private _handlerFb: DcsFallbackHandlerType = () => {};
public dispose(): void { public dispose(): void {
this._handlers = Object.create(null); this._handlers = Object.create(null);
@@ -46,7 +46,7 @@ export class DcsParser implements IDcsParser {
if (this._handlers[ident]) delete this._handlers[ident]; if (this._handlers[ident]) delete this._handlers[ident];
} }
public setHandlerFallback(handler: DcsFallbackHandler): void { public setHandlerFallback(handler: DcsFallbackHandlerType): void {
this._handlerFb = handler; this._handlerFb = handler;
} }
@@ -3,7 +3,7 @@
* @license MIT * @license MIT
*/ */
import { IParsingState, IParams, ParamsArray, IOscParser, IOscHandler, OscFallbackHandler } from 'common/parser/Types'; import { IParsingState, IParams, ParamsArray, IOscParser, IOscHandler, OscFallbackHandlerType } from 'common/parser/Types';
import { EscapeSequenceParser, TransitionTable, VT500_TRANSITION_TABLE } from 'common/parser/EscapeSequenceParser'; import { EscapeSequenceParser, TransitionTable, VT500_TRANSITION_TABLE } from 'common/parser/EscapeSequenceParser';
import * as chai from 'chai'; import * as chai from 'chai';
import { StringToUtf32, stringFromCodePoint, utf32ToString } from 'common/input/TextDecoder'; import { StringToUtf32, stringFromCodePoint, utf32ToString } from 'common/input/TextDecoder';
@@ -24,7 +24,7 @@ function r(a: number, b: number): string[] {
} }
class MockOscPutParser implements IOscParser { class MockOscPutParser implements IOscParser {
private _fallback: OscFallbackHandler = () => {}; private _fallback: OscFallbackHandlerType = () => {};
public data = ''; public data = '';
public reset(): void { public reset(): void {
this.data = ''; this.data = '';
@@ -50,7 +50,7 @@ class MockOscPutParser implements IOscParser {
clearHandler(ident: number): void { clearHandler(ident: number): void {
throw new Error('not implemented'); throw new Error('not implemented');
} }
setHandlerFallback(handler: OscFallbackHandler): void { setHandlerFallback(handler: OscFallbackHandlerType): void {
this._fallback = handler; this._fallback = handler;
} }
} }
+19 -19
View File
@@ -3,7 +3,7 @@
* @license MIT * @license MIT
*/ */
import { IParsingState, IDcsHandler, IEscapeSequenceParser, IParams, IOscHandler, IHandlerCollection, CsiHandler, OscFallbackHandler, IOscParser, EscHandler, IDcsParser, DcsFallbackHandler, IFunctionIdentifier, ExecuteFallbackHandler, CsiFallbackHandler, EscFallbackHandler, PrintHandler, PrintFallbackHandler, ExecuteHandler } from 'common/parser/Types'; import { IParsingState, IDcsHandler, IEscapeSequenceParser, IParams, IOscHandler, IHandlerCollection, CsiHandlerType, OscFallbackHandlerType, IOscParser, EscHandlerType, IDcsParser, DcsFallbackHandlerType, IFunctionIdentifier, ExecuteFallbackHandlerType, CsiFallbackHandlerType, EscFallbackHandlerType, PrintHandlerType, PrintFallbackHandlerType, ExecuteHandlerType } from 'common/parser/Types';
import { ParserState, ParserAction } from 'common/parser/Constants'; import { ParserState, ParserAction } from 'common/parser/Constants';
import { Disposable } from 'common/Lifecycle'; import { Disposable } from 'common/Lifecycle';
import { IDisposable } from 'common/Types'; import { IDisposable } from 'common/Types';
@@ -238,19 +238,19 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
protected _collect: number; protected _collect: number;
// handler lookup containers // handler lookup containers
protected _printHandler: PrintHandler; protected _printHandler: PrintHandlerType;
protected _executeHandlers: {[flag: number]: ExecuteHandler}; protected _executeHandlers: {[flag: number]: ExecuteHandlerType};
protected _csiHandlers: IHandlerCollection<CsiHandler>; protected _csiHandlers: IHandlerCollection<CsiHandlerType>;
protected _escHandlers: IHandlerCollection<EscHandler>; protected _escHandlers: IHandlerCollection<EscHandlerType>;
protected _oscParser: IOscParser; protected _oscParser: IOscParser;
protected _dcsParser: IDcsParser; protected _dcsParser: IDcsParser;
protected _errorHandler: (state: IParsingState) => IParsingState; protected _errorHandler: (state: IParsingState) => IParsingState;
// fallback handlers // fallback handlers
protected _printHandlerFb: PrintFallbackHandler; protected _printHandlerFb: PrintFallbackHandlerType;
protected _executeHandlerFb: ExecuteFallbackHandler; protected _executeHandlerFb: ExecuteFallbackHandlerType;
protected _csiHandlerFb: CsiFallbackHandler; protected _csiHandlerFb: CsiFallbackHandlerType;
protected _escHandlerFb: EscFallbackHandler; protected _escHandlerFb: EscFallbackHandlerType;
protected _errorHandlerFb: (state: IParsingState) => IParsingState; protected _errorHandlerFb: (state: IParsingState) => IParsingState;
constructor(readonly TRANSITIONS: TransitionTable = VT500_TRANSITION_TABLE) { constructor(readonly TRANSITIONS: TransitionTable = VT500_TRANSITION_TABLE) {
@@ -335,14 +335,14 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
this._dcsParser.dispose(); this._dcsParser.dispose();
} }
public setPrintHandler(handler: PrintHandler): void { public setPrintHandler(handler: PrintHandlerType): void {
this._printHandler = handler; this._printHandler = handler;
} }
public clearPrintHandler(): void { public clearPrintHandler(): void {
this._printHandler = this._printHandlerFb; this._printHandler = this._printHandlerFb;
} }
public addEscHandler(id: IFunctionIdentifier, handler: EscHandler): IDisposable { public addEscHandler(id: IFunctionIdentifier, handler: EscHandlerType): IDisposable {
const ident = this._identifier(id, [0x30, 0x7e]); const ident = this._identifier(id, [0x30, 0x7e]);
if (this._escHandlers[ident] === undefined) { if (this._escHandlers[ident] === undefined) {
this._escHandlers[ident] = []; this._escHandlers[ident] = [];
@@ -358,27 +358,27 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
} }
}; };
} }
public setEscHandler(id: IFunctionIdentifier, handler: EscHandler): void { public setEscHandler(id: IFunctionIdentifier, handler: EscHandlerType): void {
this._escHandlers[this._identifier(id, [0x30, 0x7e])] = [handler]; this._escHandlers[this._identifier(id, [0x30, 0x7e])] = [handler];
} }
public clearEscHandler(id: IFunctionIdentifier): void { public clearEscHandler(id: IFunctionIdentifier): void {
if (this._escHandlers[this._identifier(id, [0x30, 0x7e])]) delete this._escHandlers[this._identifier(id, [0x30, 0x7e])]; if (this._escHandlers[this._identifier(id, [0x30, 0x7e])]) delete this._escHandlers[this._identifier(id, [0x30, 0x7e])];
} }
public setEscHandlerFallback(handler: EscFallbackHandler): void { public setEscHandlerFallback(handler: EscFallbackHandlerType): void {
this._escHandlerFb = handler; this._escHandlerFb = handler;
} }
public setExecuteHandler(flag: string, handler: ExecuteHandler): void { public setExecuteHandler(flag: string, handler: ExecuteHandlerType): void {
this._executeHandlers[flag.charCodeAt(0)] = handler; this._executeHandlers[flag.charCodeAt(0)] = handler;
} }
public clearExecuteHandler(flag: string): void { public clearExecuteHandler(flag: string): void {
if (this._executeHandlers[flag.charCodeAt(0)]) delete this._executeHandlers[flag.charCodeAt(0)]; if (this._executeHandlers[flag.charCodeAt(0)]) delete this._executeHandlers[flag.charCodeAt(0)];
} }
public setExecuteHandlerFallback(handler: ExecuteFallbackHandler): void { public setExecuteHandlerFallback(handler: ExecuteFallbackHandlerType): void {
this._executeHandlerFb = handler; this._executeHandlerFb = handler;
} }
public addCsiHandler(id: IFunctionIdentifier, handler: CsiHandler): IDisposable { public addCsiHandler(id: IFunctionIdentifier, handler: CsiHandlerType): IDisposable {
const ident = this._identifier(id); const ident = this._identifier(id);
if (this._csiHandlers[ident] === undefined) { if (this._csiHandlers[ident] === undefined) {
this._csiHandlers[ident] = []; this._csiHandlers[ident] = [];
@@ -394,7 +394,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
} }
}; };
} }
public setCsiHandler(id: IFunctionIdentifier, handler: CsiHandler): void { public setCsiHandler(id: IFunctionIdentifier, handler: CsiHandlerType): void {
this._csiHandlers[this._identifier(id)] = [handler]; this._csiHandlers[this._identifier(id)] = [handler];
} }
public clearCsiHandler(id: IFunctionIdentifier): void { public clearCsiHandler(id: IFunctionIdentifier): void {
@@ -413,7 +413,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
public clearDcsHandler(id: IFunctionIdentifier): void { public clearDcsHandler(id: IFunctionIdentifier): void {
this._dcsParser.clearHandler(this._identifier(id)); this._dcsParser.clearHandler(this._identifier(id));
} }
public setDcsHandlerFallback(handler: DcsFallbackHandler): void { public setDcsHandlerFallback(handler: DcsFallbackHandlerType): void {
this._dcsParser.setHandlerFallback(handler); this._dcsParser.setHandlerFallback(handler);
} }
@@ -426,7 +426,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
public clearOscHandler(ident: number): void { public clearOscHandler(ident: number): void {
this._oscParser.clearHandler(ident); this._oscParser.clearHandler(ident);
} }
public setOscHandlerFallback(handler: OscFallbackHandler): void { public setOscHandlerFallback(handler: OscFallbackHandlerType): void {
this._oscParser.setHandlerFallback(handler); this._oscParser.setHandlerFallback(handler);
} }
+3 -3
View File
@@ -3,7 +3,7 @@
* @license MIT * @license MIT
*/ */
import { IOscHandler, IHandlerCollection, OscFallbackHandler, IOscParser } from 'common/parser/Types'; import { IOscHandler, IHandlerCollection, OscFallbackHandlerType, IOscParser } from 'common/parser/Types';
import { OscState, PAYLOAD_LIMIT } from 'common/parser/Constants'; import { OscState, PAYLOAD_LIMIT } from 'common/parser/Constants';
import { utf32ToString } from 'common/input/TextDecoder'; import { utf32ToString } from 'common/input/TextDecoder';
import { IDisposable } from 'common/Types'; import { IDisposable } from 'common/Types';
@@ -13,7 +13,7 @@ export class OscParser implements IOscParser {
private _state = OscState.START; private _state = OscState.START;
private _id = -1; private _id = -1;
private _handlers: IHandlerCollection<IOscHandler> = Object.create(null); private _handlers: IHandlerCollection<IOscHandler> = Object.create(null);
private _handlerFb: OscFallbackHandler = () => { }; private _handlerFb: OscFallbackHandlerType = () => { };
public addHandler(ident: number, handler: IOscHandler): IDisposable { public addHandler(ident: number, handler: IOscHandler): IDisposable {
if (this._handlers[ident] === undefined) { if (this._handlers[ident] === undefined) {
@@ -36,7 +36,7 @@ export class OscParser implements IOscParser {
public clearHandler(ident: number): void { public clearHandler(ident: number): void {
if (this._handlers[ident]) delete this._handlers[ident]; if (this._handlers[ident]) delete this._handlers[ident];
} }
public setHandlerFallback(handler: OscFallbackHandler): void { public setHandlerFallback(handler: OscFallbackHandlerType): void {
this._handlerFb = handler; this._handlerFb = handler;
} }
+28 -28
View File
@@ -65,6 +65,13 @@ export interface IParsingState {
* Command handler interfaces. * Command handler interfaces.
*/ */
/**
* CSI handler types.
* Note: `params` is borrowed.
*/
export type CsiHandlerType = (params: IParams) => boolean | void;
export type CsiFallbackHandlerType = (ident: number, params: IParams) => void;
/** /**
* DCS handler types. * DCS handler types.
*/ */
@@ -88,26 +95,19 @@ export interface IDcsHandler {
*/ */
unhook(success: boolean): void | boolean; unhook(success: boolean): void | boolean;
} }
export type DcsFallbackHandler = (ident: number, action: 'HOOK' | 'PUT' | 'UNHOOK', payload?: any) => void; export type DcsFallbackHandlerType = (ident: number, action: 'HOOK' | 'PUT' | 'UNHOOK', payload?: any) => void;
/** /**
* ESC handler types. * ESC handler types.
*/ */
export type EscHandler = () => boolean | void; export type EscHandlerType = () => boolean | void;
export type EscFallbackHandler = (identifier: number) => void; export type EscFallbackHandlerType = (identifier: number) => void;
/** /**
* EXECUTE handler types. * EXECUTE handler types.
*/ */
export type ExecuteHandler = () => boolean | void; export type ExecuteHandlerType = () => boolean | void;
export type ExecuteFallbackHandler = (ident: number) => void; export type ExecuteFallbackHandlerType = (ident: number) => void;
/**
* CSI handler types.
* Note: `params` is borrowed.
*/
export type CsiHandler = (params: IParams) => boolean | void;
export type CsiFallbackHandler = (ident: number, params: IParams) => void;
/** /**
* OSC handler types. * OSC handler types.
@@ -131,13 +131,13 @@ export interface IOscHandler {
*/ */
end(success: boolean): void | boolean; end(success: boolean): void | boolean;
} }
export type OscFallbackHandler = (ident: number, action: 'START' | 'PUT' | 'END', payload?: any) => void; export type OscFallbackHandlerType = (ident: number, action: 'START' | 'PUT' | 'END', payload?: any) => void;
/** /**
* PRINT handler types. * PRINT handler types.
*/ */
export type PrintHandler = (data: Uint32Array, start: number, end: number) => void; export type PrintHandlerType = (data: Uint32Array, start: number, end: number) => void;
export type PrintFallbackHandler = PrintHandler; export type PrintFallbackHandlerType = PrintHandlerType;
/** /**
@@ -171,31 +171,31 @@ export interface IEscapeSequenceParser extends IDisposable {
*/ */
identToString(ident: number): string; identToString(ident: number): string;
setPrintHandler(handler: PrintHandler): void; setPrintHandler(handler: PrintHandlerType): void;
clearPrintHandler(): void; clearPrintHandler(): void;
setEscHandler(id: IFunctionIdentifier, handler: EscHandler): void; setEscHandler(id: IFunctionIdentifier, handler: EscHandlerType): void;
clearEscHandler(id: IFunctionIdentifier): void; clearEscHandler(id: IFunctionIdentifier): void;
setEscHandlerFallback(handler: EscFallbackHandler): void; setEscHandlerFallback(handler: EscFallbackHandlerType): void;
addEscHandler(id: IFunctionIdentifier, handler: EscHandler): IDisposable; addEscHandler(id: IFunctionIdentifier, handler: EscHandlerType): IDisposable;
setExecuteHandler(flag: string, handler: ExecuteHandler): void; setExecuteHandler(flag: string, handler: ExecuteHandlerType): void;
clearExecuteHandler(flag: string): void; clearExecuteHandler(flag: string): void;
setExecuteHandlerFallback(handler: ExecuteFallbackHandler): void; setExecuteHandlerFallback(handler: ExecuteFallbackHandlerType): void;
setCsiHandler(id: IFunctionIdentifier, handler: CsiHandler): void; setCsiHandler(id: IFunctionIdentifier, handler: CsiHandlerType): void;
clearCsiHandler(id: IFunctionIdentifier): void; clearCsiHandler(id: IFunctionIdentifier): void;
setCsiHandlerFallback(callback: CsiFallbackHandler): void; setCsiHandlerFallback(callback: CsiFallbackHandlerType): void;
addCsiHandler(id: IFunctionIdentifier, handler: CsiHandler): IDisposable; addCsiHandler(id: IFunctionIdentifier, handler: CsiHandlerType): IDisposable;
setDcsHandler(id: IFunctionIdentifier, handler: IDcsHandler): void; setDcsHandler(id: IFunctionIdentifier, handler: IDcsHandler): void;
clearDcsHandler(id: IFunctionIdentifier): void; clearDcsHandler(id: IFunctionIdentifier): void;
setDcsHandlerFallback(handler: DcsFallbackHandler): void; setDcsHandlerFallback(handler: DcsFallbackHandlerType): void;
addDcsHandler(id: IFunctionIdentifier, handler: IDcsHandler): IDisposable; addDcsHandler(id: IFunctionIdentifier, handler: IDcsHandler): IDisposable;
setOscHandler(ident: number, handler: IOscHandler): void; setOscHandler(ident: number, handler: IOscHandler): void;
clearOscHandler(ident: number): void; clearOscHandler(ident: number): void;
setOscHandlerFallback(handler: OscFallbackHandler): void; setOscHandlerFallback(handler: OscFallbackHandlerType): void;
addOscHandler(ident: number, handler: IOscHandler): IDisposable; addOscHandler(ident: number, handler: IOscHandler): IDisposable;
setErrorHandler(handler: (state: IParsingState) => IParsingState): void; setErrorHandler(handler: (state: IParsingState) => IParsingState): void;
@@ -216,12 +216,12 @@ export interface ISubParser<T, U> extends IDisposable {
put(data: Uint32Array, start: number, end: number): void; put(data: Uint32Array, start: number, end: number): void;
} }
export interface IOscParser extends ISubParser<IOscHandler, OscFallbackHandler> { export interface IOscParser extends ISubParser<IOscHandler, OscFallbackHandlerType> {
start(): void; start(): void;
end(success: boolean): void; end(success: boolean): void;
} }
export interface IDcsParser extends ISubParser<IDcsHandler, DcsFallbackHandler> { export interface IDcsParser extends ISubParser<IDcsHandler, DcsFallbackHandlerType> {
hook(ident: number, params: IParams): void; hook(ident: number, params: IParams): void;
unhook(success: boolean): void; unhook(success: boolean): void;
} }