Merge branch 'master' into async_handlers

This commit is contained in:
Jörg Breitbart
2021-01-22 17:49:31 +01:00
9 changed files with 604 additions and 471 deletions
+16 -32
View File
@@ -280,7 +280,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
this._errorHandler = this._errorHandlerFb;
// swallow 7bit ST (ESC+\)
this.setEscHandler({final: '\\'}, () => {});
this.registerEscHandler({final: '\\'}, () => true);
}
protected _identifier(id: IFunctionIdentifier, finalRange: number[] = [0x40, 0x7e]): number {
@@ -344,7 +344,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
this._printHandler = this._printHandlerFb;
}
public addEscHandler(id: IFunctionIdentifier, handler: EscHandlerType): IDisposable {
public registerEscHandler(id: IFunctionIdentifier, handler: EscHandlerType): IDisposable {
const ident = this._identifier(id, [0x30, 0x7e]);
if (this._escHandlers[ident] === undefined) {
this._escHandlers[ident] = [];
@@ -360,9 +360,6 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
}
};
}
public setEscHandler(id: IFunctionIdentifier, handler: EscHandlerType): void {
this._escHandlers[this._identifier(id, [0x30, 0x7e])] = [handler];
}
public clearEscHandler(id: IFunctionIdentifier): void {
if (this._escHandlers[this._identifier(id, [0x30, 0x7e])]) delete this._escHandlers[this._identifier(id, [0x30, 0x7e])];
}
@@ -380,7 +377,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
this._executeHandlerFb = handler;
}
public addCsiHandler(id: IFunctionIdentifier, handler: CsiHandlerType): IDisposable {
public registerCsiHandler(id: IFunctionIdentifier, handler: CsiHandlerType): IDisposable {
const ident = this._identifier(id);
if (this._csiHandlers[ident] === undefined) {
this._csiHandlers[ident] = [];
@@ -396,9 +393,6 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
}
};
}
public setCsiHandler(id: IFunctionIdentifier, handler: CsiHandlerType): void {
this._csiHandlers[this._identifier(id)] = [handler];
}
public clearCsiHandler(id: IFunctionIdentifier): void {
if (this._csiHandlers[this._identifier(id)]) delete this._csiHandlers[this._identifier(id)];
}
@@ -406,11 +400,8 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
this._csiHandlerFb = callback;
}
public addDcsHandler(id: IFunctionIdentifier, handler: IDcsHandler): IDisposable {
return this._dcsParser.addHandler(this._identifier(id), handler);
}
public setDcsHandler(id: IFunctionIdentifier, handler: IDcsHandler): void {
this._dcsParser.setHandler(this._identifier(id), handler);
public registerDcsHandler(id: IFunctionIdentifier, handler: IDcsHandler): IDisposable {
return this._dcsParser.registerHandler(this._identifier(id), handler);
}
public clearDcsHandler(id: IFunctionIdentifier): void {
this._dcsParser.clearHandler(this._identifier(id));
@@ -419,11 +410,8 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
this._dcsParser.setHandlerFallback(handler);
}
public addOscHandler(ident: number, handler: IOscHandler): IDisposable {
return this._oscParser.addHandler(ident, handler);
}
public setOscHandler(ident: number, handler: IOscHandler): void {
this._oscParser.setHandler(ident, handler);
public registerOscHandler(ident: number, handler: IOscHandler): IDisposable {
return this._oscParser.registerHandler(ident, handler);
}
public clearOscHandler(ident: number): void {
this._oscParser.clearHandler(ident);
@@ -622,14 +610,11 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
let j = handlers ? handlers.length - 1 : -1;
for (; j >= 0; j--) {
// undefined or true means success and to stop bubbling
// FIXME: remove setHandler interface, always use addHandler with proper return value in true|false
// background - result of undefined leads to nonsense instanceof Promise test below
if ((res = handlers[j](params)) !== false) {
if (res && res instanceof Promise) {
this._preserveStack('CSI', handlers, j, transition, currentState, collect, i);
return res;
}
if ((res = handlers[j](params)) === true) {
break;
} else if (res instanceof Promise) {
this._preserveStack('CSI', handlers, j, transition, currentState, collect, i);
return res;
}
}
if (j < 0) {
@@ -662,12 +647,11 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
let jj = handlersEsc ? handlersEsc.length - 1 : -1;
for (; jj >= 0; jj--) {
// undefined or true means success and to stop bubbling
if ((res = handlersEsc[jj]()) !== false) {
if (res && res instanceof Promise) {
this._preserveStack('ESC', handlersEsc, jj, transition, currentState, collect, i);
return res;
}
if ((res = handlersEsc[jj]()) === true) {
break;
} else if (res instanceof Promise) {
this._preserveStack('ESC', handlersEsc, jj, transition, currentState, collect, i);
return res;
}
}
if (jj < 0) {
@@ -708,7 +692,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
case ParserAction.OSC_PUT:
// inner loop: 0x20 (SP) included, 0x7F (DEL) included
for (let j = i + 1; ; j++) {
if (j >= length || (code = data[j]) < 0x20 || (code > 0x7f && code <= 0x9f)) {
if (j >= length || (code = data[j]) < 0x20 || (code > 0x7f && code < NON_ASCII_PRINTABLE)) {
osc.put(data, i, j);
i = j - 1;
break;