Skip to content

Commit

Permalink
support Pseudoterminal.onDidChangeName (#11657)
Browse files Browse the repository at this point in the history
The commit adds support for the `Pseudoterminal.onDidChangeName` VS Code API.
  • Loading branch information
EstFoisy authored Sep 14, 2022
1 parent c068f79 commit 2289366
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ export interface TerminalServiceMain {
*/
$dispose(id: string): void;

/**
* Set the terminal widget name.
* @param id terminal widget id.
* @param name new terminal widget name.
*/
$setName(id: string, name: string): void;

/**
* Send text to the terminal by id.
* @param id - terminal id.
Expand Down Expand Up @@ -377,6 +384,13 @@ export interface TerminalServiceMain {
$disposeByTerminalId(id: number, waitOnExit?: boolean | string): void;

$setEnvironmentVariableCollection(extensionIdentifier: string, persistent: boolean, collection: SerializableEnvironmentVariableCollection | undefined): void;

/**
* Set the terminal widget name.
* @param id terminal id.
* @param name new terminal widget name.
*/
$setNameByTerminalId(id: number, name: string): void;
}

export interface AutoFocus {
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-ext/src/main/browser/terminal-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, Disposable
}
}

$setName(id: string, name: string): void {
this.terminals.getById(id)?.setTitle(name);
}

$sendTextByTerminalId(id: number, text: string, addNewLine?: boolean): void {
const terminal = this.terminals.getByTerminalId(id);
if (terminal) {
Expand Down Expand Up @@ -232,4 +236,8 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, Disposable
terminal.dispose();
}
}

$setNameByTerminalId(id: number, name: string): void {
this.terminals.getByTerminalId(id)?.setTitle(name);
}
}
9 changes: 9 additions & 0 deletions packages/plugin-ext/src/plugin/terminal-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ export class PseudoTerminal {
}
});
}
if (pseudoTerminal.onDidChangeName) {
pseudoTerminal.onDidChangeName(name => {
if (typeof id === 'string') {
this.proxy.$setName(id, name);
} else {
this.proxy.$setNameByTerminalId(id, name);
}
});
}
}

emitOnClose(): void {
Expand Down
20 changes: 20 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3091,6 +3091,26 @@ export module '@theia/plugin' {
*/
onDidClose?: Event<void | number>;

/**
* An event that when fired allows changing the name of the terminal.
*
* Events fired before {@link Pseudoterminal.open} is called will be be ignored.
*
* **Example:** Change the terminal name to "My new terminal".
* ```typescript
* const writeEmitter = new vscode.EventEmitter<string>();
* const changeNameEmitter = new vscode.EventEmitter<string>();
* const pty: vscode.Pseudoterminal = {
* onDidWrite: writeEmitter.event,
* onDidChangeName: changeNameEmitter.event,
* open: () => changeNameEmitter.fire('My new terminal'),
* close: () => {}
* };
* vscode.window.createTerminal({ name: 'My terminal', pty });
* ```
*/
onDidChangeName?: Event<string>;

/**
* Implement to handle when the pty is opened.
*
Expand Down

0 comments on commit 2289366

Please sign in to comment.