Add registerApcHandler to public api

This commit is contained in:
Anthony Kim
2026-01-21 10:42:36 -08:00
parent 48df6117ed
commit 8e29591b9f
5 changed files with 31 additions and 0 deletions
+3
View File
@@ -107,6 +107,9 @@ export class MockTerminal implements ITerminal {
public registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
throw new Error('Method not implemented.');
}
public registerApcHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
throw new Error('Method not implemented.');
}
public registerLinkProvider(linkProvider: ILinkProvider): IDisposable {
throw new Error('Method not implemented.');
}
+5
View File
@@ -242,6 +242,11 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
return this._inputHandler.registerOscHandler(ident, callback);
}
/** Add handler for APC escape sequence. See xterm.d.ts for details. */
public registerApcHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
return this._inputHandler.registerApcHandler(ident, callback);
}
protected _setup(): void {
this._handleWindowsPtyOptionChange();
}
+2
View File
@@ -22,6 +22,7 @@ export interface ICoreTerminal {
registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean | Promise<boolean>): IDisposable;
registerEscHandler(id: IFunctionIdentifier, callback: () => boolean | Promise<boolean>): IDisposable;
registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
registerApcHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
}
export interface IDisposable {
@@ -475,6 +476,7 @@ export interface IInputHandler {
registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean | Promise<boolean>): IDisposable;
registerEscHandler(id: IFunctionIdentifier, callback: () => boolean | Promise<boolean>): IDisposable;
registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
registerApcHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
/** C0 BEL */ bell(): boolean;
/** C0 LF */ lineFeed(): boolean;
+3
View File
@@ -34,4 +34,7 @@ export class ParserApi implements IParser {
public addOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
return this.registerOscHandler(ident, callback);
}
public registerApcHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
return this._core.registerApcHandler(ident, callback);
}
}
+18
View File
@@ -1932,6 +1932,24 @@ declare module '@xterm/xterm' {
* @returns An IDisposable you can call to remove this handler.
*/
registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
/**
* Adds a handler for APC escape sequences.
* @param ident The identifier (first character) of the sequence as a
* character code, e.g. 71 for 'G' (Kitty graphics protocol).
* @param callback The function to handle the sequence. Note that the
* function will only be called once if the sequence finished successfully.
* There is currently no way to intercept smaller data chunks, data chunks
* will be stored up until the sequence is finished. Since APC sequences are
* not limited by the amount of data this might impose a problem for big
* payloads. Currently xterm.js limits APC payload to 10 MB which should
* give enough room for most use cases. The callback is called with APC data
* string (excluding the identifier character). Return `true` if the
* sequence was handled, `false` if the parser should try a previous
* handler. The most recently added handler is tried first.
* @returns An IDisposable you can call to remove this handler.
*/
registerApcHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
}
/**