From fcd65cc862bed7bddfc43f24f938ff62406e9cd4 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 2 Jun 2017 14:33:24 -0700 Subject: [PATCH] Ensure terminal pty is ready before sendText is called Fixes #27939 --- .../electron-browser/terminalInstance.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts index bb4237e7aad..4b70c062ba8 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts @@ -31,6 +31,7 @@ import { TerminalLinkHandler } from 'vs/workbench/parts/terminal/electron-browse import { TerminalWidgetManager } from 'vs/workbench/parts/terminal/browser/terminalWidgetManager'; import { registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService'; import { scrollbarSliderBackground, scrollbarSliderHoverBackground, scrollbarSliderActiveBackground } from 'vs/platform/theme/common/colorRegistry'; +import { TPromise } from "vs/base/common/winjs.base"; /** The amount of time to consider terminal errors to be related to the launch */ const LAUNCHING_DURATION = 500; @@ -56,6 +57,7 @@ export class TerminalInstance implements ITerminalInstance { private _hadFocusOnExit: boolean; private _isLaunching: boolean; private _isVisible: boolean; + private _processReady: TPromise; private _isDisposed: boolean; private _onDisposed: Emitter; private _onDataForApi: Emitter<{ instance: ITerminalInstance, data: string }>; @@ -115,6 +117,11 @@ export class TerminalInstance implements ITerminalInstance { this._onProcessIdReady = new Emitter(); this._onTitleChanged = new Emitter(); + // Create a promise that resolves when the pty is ready + this._processReady = new TPromise(c => { + this.onProcessIdReady(() => c(void 0)); + }); + this._initDimensions(); this._createProcess(this._contextService.getWorkspace(), this._shellLaunchConfig); this._createXterm(); @@ -376,13 +383,15 @@ export class TerminalInstance implements ITerminalInstance { } public sendText(text: string, addNewLine: boolean): void { - text = this._sanitizeInput(text); - if (addNewLine && text.substr(text.length - 1) !== '\r') { - text += '\r'; - } - this._process.send({ - event: 'input', - data: text + this._processReady.then(() => { + text = this._sanitizeInput(text); + if (addNewLine && text.substr(text.length - 1) !== '\r') { + text += '\r'; + } + this._process.send({ + event: 'input', + data: text + }); }); }