Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Pseudoterminal.onDidChangeName #11657

Merged
merged 4 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 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,13 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, Disposable
}
}

$setName(id: string, name: string): void {
const terminal = this.terminals.getById(id);
if (terminal) {
terminal.setTitle(name);
}
}

$sendTextByTerminalId(id: number, text: string, addNewLine?: boolean): void {
const terminal = this.terminals.getByTerminalId(id);
if (terminal) {
Expand Down Expand Up @@ -232,4 +239,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 @@ -3081,6 +3081,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