Merge pull request #4953 from arencoskun/master

Expose API method for writing to application side (#4948)
This commit is contained in:
Daniel Imms
2024-02-02 12:16:03 -08:00
committed by GitHub
8 changed files with 42 additions and 0 deletions
+3
View File
@@ -72,6 +72,9 @@ export class MockTerminal implements ITerminal {
public focus(): void {
throw new Error('Method not implemented.');
}
public input(data: string, wasUserInput: boolean = true): void {
throw new Error('Method not implemented.');
}
public resize(columns: number, rows: number): void {
throw new Error('Method not implemented.');
}
+3
View File
@@ -138,6 +138,9 @@ export class Terminal extends Disposable implements ITerminalApi {
public focus(): void {
this._core.focus();
}
public input(data: string, wasUserInput: boolean = true): void {
this._core.input(data, wasUserInput);
}
public resize(columns: number, rows: number): void {
this._verifyIntegers(columns, rows);
this._core.resize(columns, rows);
+4
View File
@@ -168,6 +168,10 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
this._writeBuffer.writeSync(data, maxSubsequentCalls);
}
public input(data: string, wasUserInput: boolean = true): void {
this.coreService.triggerDataEvent(data, wasUserInput);
}
public resize(x: number, y: number): void {
if (isNaN(x) || isNaN(y)) {
return;
+4
View File
@@ -81,6 +81,10 @@ export class Terminal extends CoreTerminal {
this._onBell.fire();
}
public input(data: string, wasUserInput: boolean = true): void {
this.coreService.triggerDataEvent(data, wasUserInput);
}
/**
* Resizes the terminal.
*
+3
View File
@@ -134,6 +134,9 @@ export class Terminal extends Disposable implements ITerminalApi {
this._publicOptions[propName] = options[propName];
}
}
public input(data: string, wasUserInput: boolean = true): void {
this._core.input(data, wasUserInput);
}
public resize(columns: number, rows: number): void {
this._verifyIntegers(columns, rows);
this._core.resize(columns, rows);
+1
View File
@@ -216,6 +216,7 @@ export class TerminalProxy implements ITerminalProxyCustomMethods, PlaywrightApi
return new Promise(r => term.writeln(typeof data === 'string' ? data : new Uint8Array(data), r));
}, [await this.getHandle(), typeof data === 'string' ? data : Array.from(data)] as const);
}
public async input(data: string, wasUserInput: boolean = true): Promise<void> { return this.evaluate(([term]) => term.input(data, wasUserInput)); }
public async resize(cols: number, rows: number): Promise<void> { return this._page.evaluate(([term, cols, rows]) => term.resize(cols, rows), [await this.getHandle(), cols, rows] as const); }
public async registerMarker(y?: number | undefined): Promise<IMarker> { return this._page.evaluate(([term, y]) => term.registerMarker(y), [await this.getHandle(), y] as const); }
public async registerDecoration(decorationOptions: IDecorationOptions): Promise<IDecoration | undefined> { return this._page.evaluate(([term, decorationOptions]) => term.registerDecoration(decorationOptions), [await this.getHandle(), decorationOptions] as const); }
+12
View File
@@ -718,6 +718,18 @@ declare module '@xterm/headless' {
*/
onTitleChange: IEvent<string>;
/**
* Input data to application side. The data is treated the same way input
* typed into the terminal would (ie. the {@link onData} event will fire).
* @param data The data to forward to the application.
* @param wasUserInput Whether the input is genuine user input. This is true
* by default and triggers additionalbehavior like focus or selection
* clearing. Set this to false if the data sent should not be treated like
* user input would, for example passing an escape sequence to the
* application.
*/
input(data: string, wasUserInput?: boolean): void;
/**
* Resizes the terminal. It's best practice to debounce calls to resize,
* this will help ensure that the pty can respond to the resize event
+12
View File
@@ -963,6 +963,18 @@ declare module '@xterm/xterm' {
*/
focus(): void;
/**
* Input data to application side. The data is treated the same way input
* typed into the terminal would (ie. the {@link onData} event will fire).
* @param data The data to forward to the application.
* @param wasUserInput Whether the input is genuine user input. This is true
* by default and triggers additionalbehavior like focus or selection
* clearing. Set this to false if the data sent should not be treated like
* user input would, for example passing an escape sequence to the
* application.
*/
input(data: string, wasUserInput?: boolean): void;
/**
* Resizes the terminal. It's best practice to debounce calls to resize,
* this will help ensure that the pty can respond to the resize event