Skip to content

Commit

Permalink
fix #122441
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed May 5, 2021
1 parent 9ddbdf4 commit 4df0a67
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export interface IOffProcessTerminalService {
getWslPath(original: string): Promise<string>;
getEnvironment(): Promise<IProcessEnvironment>;
setTerminalLayoutInfo(layoutInfo?: ITerminalsLayoutInfoById): Promise<void>;
updateTitle(id: number, title: string): Promise<void>;
updateIcon(id: number, icon: string): Promise<void>;
getTerminalLayoutInfo(): Promise<ITerminalsLayoutInfo | undefined>;
reduceConnectionGraceTime(): Promise<void>;
}
Expand Down Expand Up @@ -160,7 +162,8 @@ export interface IPtyService {
processBinary(id: number, data: string): Promise<void>;
/** Confirm the process is _not_ an orphan. */
orphanQuestionReply(id: number): Promise<void>;

updateTitle(id: number, title: string): Promise<void>
updateIcon(id: number, icon: string): Promise<void>
getDefaultSystemShell(osOverride?: OperatingSystem): Promise<string>;
getEnvironment(): Promise<IProcessEnvironment>;
getWslPath(original: string): Promise<string>;
Expand Down
6 changes: 6 additions & 0 deletions src/vs/platform/terminal/node/ptyHostService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ export class PtyHostService extends Disposable implements IPtyService {
lastPtyId = Math.max(lastPtyId, id);
return id;
}
updateTitle(id: number, title: string): Promise<void> {
return this._proxy.updateTitle(id, title);
}
updateIcon(id: number, icon: string): Promise<void> {
return this._proxy.updateIcon(id, icon);
}
attachToProcess(id: number): Promise<void> {
return this._proxy.attachToProcess(id);
}
Expand Down
24 changes: 22 additions & 2 deletions src/vs/platform/terminal/node/ptyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ export class PtyService extends Disposable implements IPtyService {
}
}

async updateTitle(id: number, title: string): Promise<void> {
this._throwIfNoPty(id).setTitle(title);
}

async updateIcon(id: number, icon: string): Promise<void> {
this._throwIfNoPty(id).setIcon(icon);
}

async detachFromProcess(id: number): Promise<void> {
this._throwIfNoPty(id).detach();
}
Expand Down Expand Up @@ -290,10 +298,22 @@ export class PersistentTerminalProcess extends Disposable {
private _pid = -1;
private _cwd = '';

private _title: string = '';

get pid(): number { return this._pid; }
get title(): string { return this._terminalProcess.currentTitle; }
get title(): string {
return this._title || this._terminalProcess.currentTitle;
}
get icon(): string | undefined { return this._icon; }

setTitle(title: string): void {
this._title = title;
}

setIcon(icon: string): void {
this._icon = icon;
}

constructor(
private _persistentProcessId: number,
private readonly _terminalProcess: TerminalProcess,
Expand All @@ -302,7 +322,7 @@ export class PersistentTerminalProcess extends Disposable {
readonly shouldPersistTerminal: boolean,
cols: number, rows: number,
private readonly _logService: ILogService,
private readonly _icon?: string
private _icon?: string
) {
super();
this._recorder = new TerminalRecorder(cols, rows);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ export class RemoteTerminalService extends Disposable implements IRemoteTerminal
});
}

async updateTitle(id: number, title: string): Promise<void> {
await this._remoteTerminalChannel?.updateTitle(id, title);
}

async updateIcon(id: number, icon: string): Promise<void> {
await this._remoteTerminalChannel?.updateIcon(id, icon);
}

async getDefaultSystemShell(osOverride?: OperatingSystem): Promise<string> {
return this._remoteTerminalChannel?.getDefaultSystemShell(osOverride) || '';
}
Expand Down
6 changes: 6 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface ITerminalService {
onInstanceRequestStartExtensionTerminal: Event<IStartExtensionTerminalRequest>;
onInstancesChanged: Event<void>;
onInstanceTitleChanged: Event<ITerminalInstance | undefined>;
onInstanceIconChanged: Event<ITerminalInstance | undefined>;
onInstancePrimaryStatusChanged: Event<ITerminalInstance>;
onActiveInstanceChanged: Event<ITerminalInstance | undefined>;
onRequestAvailableProfiles: Event<IAvailableProfilesRequest>;
Expand Down Expand Up @@ -286,6 +287,11 @@ export interface ITerminalInstance {
*/
onTitleChanged: Event<ITerminalInstance>;

/**
* An event that fires when the terminal instance's icon changes.
*/
onIconChanged: Event<ITerminalInstance>;

/**
* An event that fires when the terminal instance is disposed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
get onLinksReady(): Event<ITerminalInstance> { return this._onLinksReady.event; }
private readonly _onTitleChanged = new Emitter<ITerminalInstance>();
get onTitleChanged(): Event<ITerminalInstance> { return this._onTitleChanged.event; }
private readonly _onIconChanged = new Emitter<ITerminalInstance>();
get onIconChanged(): Event<ITerminalInstance> { return this._onIconChanged.event; }
private readonly _onData = new Emitter<string>();
get onData(): Event<string> { return this._onData.event; }
private readonly _onBinary = new Emitter<string>();
Expand Down Expand Up @@ -1779,7 +1781,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
});
if (result) {
this.shellLaunchConfig.icon = result.description;
this._onTitleChanged.fire(this);
this._onIconChanged.fire(this);
}
}

Expand Down
37 changes: 37 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export class TerminalService implements ITerminalService {
get onInstancesChanged(): Event<void> { return this._onInstancesChanged.event; }
private readonly _onInstanceTitleChanged = new Emitter<ITerminalInstance | undefined>();
get onInstanceTitleChanged(): Event<ITerminalInstance | undefined> { return this._onInstanceTitleChanged.event; }
private readonly _onInstanceIconChanged = new Emitter<ITerminalInstance | undefined>();
get onInstanceIconChanged(): Event<ITerminalInstance | undefined> { return this._onInstanceIconChanged.event; }
private readonly _onActiveInstanceChanged = new Emitter<ITerminalInstance | undefined>();
get onActiveInstanceChanged(): Event<ITerminalInstance | undefined> { return this._onActiveInstanceChanged.event; }
private readonly _onInstancePrimaryStatusChanged = new Emitter<ITerminalInstance>();
Expand Down Expand Up @@ -300,6 +302,22 @@ export class TerminalService implements ITerminalService {
// The state must be updated when the terminal is relaunched, otherwise the persistent
// terminal ID will be stale and the process will be leaked.
this.onInstanceProcessIdReady(() => isRemote ? this._updateRemoteState() : this._updateLocalState());
this.onInstanceTitleChanged(instance => {
this._updateTitle(instance);
if (isRemote) {
this._updateRemoteState();
} else {
this._updateLocalState();
}
});
this.onInstanceIconChanged(instance => {
this._updateIcon(instance);
if (isRemote) {
this._updateRemoteState();
} else {
this._updateLocalState();
}
});
}

private _handleInstanceContextKeys(): void {
Expand Down Expand Up @@ -420,6 +438,24 @@ export class TerminalService implements ITerminalService {
}
}

@debounce(500)
private _updateTitle(instance?: ITerminalInstance): void {
if (!instance?.persistentProcessId || !instance?.title) {
return;
}
this._localTerminalService!.updateTitle(instance.persistentProcessId, instance.title);
this._updateLocalState();
}

@debounce(500)
private _updateIcon(instance?: ITerminalInstance): void {
if (!instance?.persistentProcessId || !instance?.icon) {
return;
}
this._localTerminalService!.updateIcon(instance.persistentProcessId, instance.icon.id);
this._updateLocalState();
}

@debounce(500)
private _updateLocalState(): void {
const state: ITerminalsLayoutInfoById = {
Expand Down Expand Up @@ -630,6 +666,7 @@ export class TerminalService implements ITerminalService {
protected _initInstanceListeners(instance: ITerminalInstance): void {
instance.addDisposable(instance.onDisposed(this._onInstanceDisposed.fire, this._onInstanceDisposed));
instance.addDisposable(instance.onTitleChanged(this._onInstanceTitleChanged.fire, this._onInstanceTitleChanged));
instance.addDisposable(instance.onIconChanged(this._onInstanceIconChanged.fire, this._onInstanceIconChanged));
instance.addDisposable(instance.onProcessIdReady(this._onInstanceProcessIdReady.fire, this._onInstanceProcessIdReady));
instance.addDisposable(instance.statusList.onDidChangePrimaryStatus(() => this._onInstancePrimaryStatusChanged.fire(instance)));
instance.addDisposable(instance.onLinksReady(this._onInstanceLinksReady.fire, this._onInstanceLinksReady));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class TerminalTabList extends WorkbenchList<ITerminalInstance> {
);
this._terminalService.onInstancesChanged(() => this._render());
this._terminalService.onInstanceTitleChanged(() => this._render());
this._terminalService.onInstanceIconChanged(() => this._render());
this._terminalService.onActiveInstanceChanged(e => {
if (e) {
const i = this._terminalService.terminalInstances.indexOf(e);
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminalView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ class SingleTerminalTabActionViewItem extends ActionViewItem {
this.updateLabel();
}
}));
this._register(this._terminalService.onInstanceIconChanged(e => {
if (e === this._terminalService.getActiveInstance()) {
this.updateLabel();
}
}));
}

override updateLabel(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ export class RemoteTerminalChannelClient {
return this._channel.call<void>('$setTerminalLayoutInfo', args);
}

updateTitle(id: number, title: string): Promise<string> {
return this._channel.call('$updateTitle', { id, title });
}

updateIcon(id: number, icon: string): Promise<string> {
return this._channel.call('$updateIcon', { id, icon });
}

getTerminalLayoutInfo(): Promise<ITerminalsLayoutInfo | undefined> {
const workspace = this._workspaceContextService.getWorkspace();
const args: IGetTerminalLayoutInfoArgs = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ export class LocalTerminalService extends Disposable implements ILocalTerminalSe
}));
}
}
async updateTitle(id: number, title: string): Promise<void> {
await this._localPtyService.updateTitle(id, title);
}

async updateIcon(id: number, icon: string): Promise<void> {
await this._localPtyService.updateIcon(id, icon);
}

async createProcess(shellLaunchConfig: IShellLaunchConfig, cwd: string, cols: number, rows: number, env: IProcessEnvironment, windowsEnableConpty: boolean, shouldPersist: boolean): Promise<ITerminalChildProcess> {
const executableEnv = await this._shellEnvironmentService.getShellEnv();
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/test/browser/workbenchTestServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,8 @@ export class TestLocalTerminalService implements ILocalTerminalService {
async getTerminalLayoutInfo(): Promise<ITerminalsLayoutInfo | undefined> { throw new Error('Method not implemented.'); }
async reduceConnectionGraceTime(): Promise<void> { throw new Error('Method not implemented.'); }
processBinary(id: number, data: string): Promise<void> { throw new Error('Method not implemented.'); }
updateTitle(id: number, title: string): Promise<void> { throw new Error('Method not implemented.'); }
updateIcon(id: number, icon: string): Promise<void> { throw new Error('Method not implemented.'); }
}

class TestTerminalChildProcess implements ITerminalChildProcess {
Expand Down

0 comments on commit 4df0a67

Please sign in to comment.