This commit is contained in:
Daniel Imms
2017-06-12 15:27:13 -07:00
parent d57c6a1b38
commit 354042ac2a
2 changed files with 10 additions and 10 deletions
@@ -581,6 +581,5 @@ export class RenameTerminalAction extends Action {
terminalInstance.setTitle(name);
}
});
}
}
@@ -62,7 +62,6 @@ export class TerminalInstance implements ITerminalInstance {
private _isDisposed: boolean;
private _onDisposed: Emitter<ITerminalInstance>;
private _onDataForApi: Emitter<{ instance: ITerminalInstance, data: string }>;
private _onMessageTitleCheck: (message: any) => void;
private _onProcessIdReady: Emitter<TerminalInstance>;
private _onTitleChanged: Emitter<string>;
private _process: cp.ChildProcess;
@@ -77,6 +76,7 @@ export class TerminalInstance implements ITerminalInstance {
private _terminalHasTextContextKey: IContextKey<boolean>;
private _cols: number;
private _rows: number;
private _messageTitleListener: (message: { type: string, content: string }) => void;
private _widgetManager: TerminalWidgetManager;
private _linkHandler: TerminalLinkHandler;
@@ -495,13 +495,13 @@ export class TerminalInstance implements ITerminalInstance {
});
if (!shell.name) {
// Only listen for process title changes when a name is not provided
this._onMessageTitleCheck = (message) => {
this._messageTitleListener = (message) => {
if (message.type === 'title') {
this._title = message.content ? message.content : '';
this._onTitleChanged.fire(this._title);
}
};
this._process.on('message', this._onMessageTitleCheck);
this._process.on('message', this._messageTitleListener);
}
this._process.on('message', (message) => {
if (message.type === 'pid') {
@@ -782,15 +782,16 @@ export class TerminalInstance implements ITerminalInstance {
}
public setTitle(title: string): void {
const oldTitle = this._title;
if (title !== oldTitle) {
this._title = title;
const didTitleChange = title !== this._title;
if (didTitleChange) {
this._onTitleChanged.fire(title);
}
// if the title is set via API, unregister the handler that automatically updates the terminal name
if (this._process) {
this._process.removeListener('message', this._onMessageTitleCheck);
// If the title was not set by the API, unregister the handler that
// automatically updates the terminal name
if (this._process && this._messageTitleListener) {
this._process.removeListener('message', this._messageTitleListener);
this._messageTitleListener = null;
}
}
}