From ade7f5e85a85b1df525c906d08106b70110e096d Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 14 Apr 2018 04:01:42 -0700 Subject: [PATCH] Allow process not to be created --- .../parts/terminal/common/terminal.ts | 1 - .../electron-browser/terminalInstance.ts | 29 ++++++++++++------- .../terminalProcessManager.ts | 4 +-- .../terminal/electron-browser/terminalTab.ts | 6 ++-- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/vs/workbench/parts/terminal/common/terminal.ts b/src/vs/workbench/parts/terminal/common/terminal.ts index 83dc5dbaf97..48619cd6b40 100644 --- a/src/vs/workbench/parts/terminal/common/terminal.ts +++ b/src/vs/workbench/parts/terminal/common/terminal.ts @@ -472,7 +472,6 @@ export interface ITerminalProcessManager extends IDisposable { onShellProcessIdReady: Event; initialCwd: string; - acceptProcessMessage(message): void; addDisposable(disposable: IDisposable); createProcess(shellLaunchConfig: IShellLaunchConfig); write(data: string): void; diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts index 7c04b4b1ab8..b5c95e73bde 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts @@ -95,6 +95,7 @@ export class TerminalInstance implements ITerminalInstance { private _configHelper: TerminalConfigHelper, private _container: HTMLElement, private _shellLaunchConfig: IShellLaunchConfig, + doCreateProcess: boolean, @IContextKeyService private readonly _contextKeyService: IContextKeyService, @IKeybindingService private readonly _keybindingService: IKeybindingService, @INotificationService private readonly _notificationService: INotificationService, @@ -119,18 +120,12 @@ export class TerminalInstance implements ITerminalInstance { this._logService.trace(`terminalInstance#ctor (id: ${this.id})`, this._shellLaunchConfig); this._initDimensions(); - this._createProcess(); + if (doCreateProcess) { + this._createProcess(); + } this._xtermReadyPromise = this._createXterm(); this._xtermReadyPromise.then(() => { - if (platform.isWindows) { - this._processManager.ptyProcessReady.then(() => { - if (!this._isDisposed) { - this._windowsShellHelper = new WindowsShellHelper(this._processManager.shellProcessId, this, this._xterm); - } - }); - } - // Only attach xterm.js to the DOM if the terminal panel has been opened before. if (_container) { this._attachToElement(_container); @@ -269,8 +264,10 @@ export class TerminalInstance implements ITerminalInstance { } this._xterm.winptyCompatInit(); this._xterm.on('linefeed', () => this._onLineFeed()); - this._processManager.process.on('message', (message) => this._sendPtyDataToXterm(message)); - this._xterm.on('data', data => this._processManager.write(data)); + if (this._processManager) { + this._processManager.process.on('message', (message) => this._sendPtyDataToXterm(message)); + this._xterm.on('data', data => this._processManager.write(data)); + } this._linkHandler = this._instantiationService.createInstance(TerminalLinkHandler, this._xterm, platform.platform, this._processManager.initialCwd); this._commandTracker = new TerminalCommandTracker(this._xterm); this._instanceDisposables.push(this._themeService.onThemeChange(theme => this._updateTheme(theme))); @@ -611,6 +608,16 @@ export class TerminalInstance implements ITerminalInstance { this._processManager.process.on('message', this._messageTitleListener); } this._processManager.process.on('exit', exitCode => this._onPtyProcessExit(exitCode)); + + if (platform.isWindows) { + this._processManager.ptyProcessReady.then(() => { + this._xtermReadyPromise.then(() => { + if (!this._isDisposed) { + this._windowsShellHelper = new WindowsShellHelper(this._processManager.shellProcessId, this, this._xterm); + } + }); + }); + } } private _sendPtyDataToXterm(message: { type: string, content: string }): void { diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts index c4104df6742..670789b4de3 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalProcessManager.ts @@ -100,7 +100,7 @@ export class TerminalProcessManager implements ITerminalProcessManager { this.processState = ProcessState.LAUNCHING; // TODO: Hide message communication details inside terminal process manager - this.process.on('message', message => this.acceptProcessMessage(message)); + this.process.on('message', message => this._onProcessMessage(message)); setTimeout(() => { if (this.processState === ProcessState.LAUNCHING) { @@ -150,7 +150,7 @@ export class TerminalProcessManager implements ITerminalProcessManager { } } - public acceptProcessMessage(message: ITerminalProcessMessage): void { + private _onProcessMessage(message: ITerminalProcessMessage): void { if (message.type === 'pid') { this.shellProcessId = message.content; this._onShellProcessIdReady.fire(this.shellProcessId); diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalTab.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalTab.ts index 55eb0c497b3..5a9e8e95c8c 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalTab.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalTab.ts @@ -270,7 +270,8 @@ export class TerminalTab extends Disposable implements ITerminalTab { terminalFocusContextKey, configHelper, undefined, - shellLaunchConfig); + shellLaunchConfig, + true); this._terminalInstances.push(instance); this._initInstanceListeners(instance); this._activeInstanceIndex = 0; @@ -399,7 +400,8 @@ export class TerminalTab extends Disposable implements ITerminalTab { terminalFocusContextKey, configHelper, undefined, - shellLaunchConfig); + shellLaunchConfig, + true); this._terminalInstances.splice(this._activeInstanceIndex + 1, 0, instance); this._initInstanceListeners(instance); this._setActiveInstance(instance); -- GitLab