Skip to content

Commit

Permalink
Move function to CoreTerminal, add additional argument to specify if …
Browse files Browse the repository at this point in the history
…the input was user input or not.
  • Loading branch information
arencoskun committed Feb 1, 2024
1 parent 09a0dd6 commit cae4277
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
10 changes: 0 additions & 10 deletions src/browser/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1192,16 +1192,6 @@ export class Terminal extends CoreTerminal implements ITerminal {
return false;
}

/**
* Input data to application side.
* The data is treated the same way as typed input at the terminal.
* (will appear in the onData event).
*/
public input(data: string): void {
this.coreService.triggerDataEvent(data, true);
this.write(data);
}

/**
* Resizes the terminal.
*
Expand Down
2 changes: 1 addition & 1 deletion src/browser/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class MockTerminal implements ITerminal {
public focus(): void {
throw new Error('Method not implemented.');
}
public input(data: string): void {
public input(data: string, wasUserInput: boolean = true): void {
throw new Error('Method not implemented.');
}
public resize(columns: number, rows: number): void {
Expand Down
4 changes: 2 additions & 2 deletions src/browser/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ export class Terminal extends Disposable implements ITerminalApi {
public focus(): void {
this._core.focus();
}
public input(data: string): void {
this._core.input(data);
public input(data: string, wasUserInput: boolean = true): void {
this._core.input(data, wasUserInput);
}
public resize(columns: number, rows: number): void {
this._verifyIntegers(columns, rows);
Expand Down
13 changes: 13 additions & 0 deletions src/common/CoreTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
this._writeBuffer.writeSync(data, maxSubsequentCalls);
}

/**
* Input data to application side.
* The data is treated the same way as typed input at the terminal.
* (will appear in the onData event).
* wasUserInput indicates, whether the input is genuine user input.
* It is true by default and triggers additional actions like prompt focus or selection clearing.
* Set it to false if your data sent does not resemble what a user would have typed
* (e.g. sequence embedded data).
*/
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;
Expand Down
2 changes: 1 addition & 1 deletion test/playwright/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +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): Promise<void> { return this.evaluate(([term]) => term.input(data)); }
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); }
Expand Down
6 changes: 5 additions & 1 deletion typings/xterm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,12 @@ declare module '@xterm/xterm' {
/**
* Input data to application side.
* The data is treated the same way as typed input at the terminal (will appear in the onData event).

Check warning on line 968 in typings/xterm.d.ts

View workflow job for this annotation

GitHub Actions / lint

This line has a comment length of 105. Maximum allowed is 80
* wasUserInput indicates, whether the input is genuine user input.
* It is true by default and triggers additional actions like prompt focus or selection clearing.

Check warning on line 970 in typings/xterm.d.ts

View workflow job for this annotation

GitHub Actions / lint

This line has a comment length of 101. Maximum allowed is 80
* Set it to false if your data sent does not resemble what a user would have typed

Check warning on line 971 in typings/xterm.d.ts

View workflow job for this annotation

GitHub Actions / lint

This line has a comment length of 87. Maximum allowed is 80
* (e.g. sequence embedded data).
*/
input(data: string): void;
input(data: string, wasUserInput?: boolean): void;

/**
* Resizes the terminal. It's best practice to debounce calls to resize,
Expand Down

0 comments on commit cae4277

Please sign in to comment.