提交 a841b5f1 编写于 作者: D Daniel Imms

Enable process to write to terminal before the panel exists

Fixes #12000
上级 5c64c4c6
......@@ -97,7 +97,9 @@ export class TerminalInstance implements ITerminalInstance {
this._onTitleChanged = new Emitter<string>();
this._createProcess(this._contextService.getWorkspace(), this._shellLaunchConfig);
this._createXterm();
// Only attach xterm.js to the DOM if the terminal panel has been opened before.
if (_container) {
this.attachToElement(_container);
}
......@@ -107,21 +109,13 @@ export class TerminalInstance implements ITerminalInstance {
this._instanceDisposables.push(disposable);
}
public attachToElement(container: HTMLElement): void {
if (this._wrapperElement) {
throw new Error('The terminal instance has already been attached to a container');
}
this._container = container;
this._wrapperElement = document.createElement('div');
DOM.addClass(this._wrapperElement, 'terminal-wrapper');
this._xtermElement = document.createElement('div');
/**
* Create xterm.js instance and attach data listeners.
*/
protected _createXterm(): void {
this._xterm = xterm({
scrollback: this._configHelper.getScrollback()
});
this._xterm.open(this._xtermElement);
this._process.on('message', (message) => this._sendPtyDataToXterm(message));
this._xterm.on('data', (data) => {
if (this._process) {
......@@ -132,6 +126,19 @@ export class TerminalInstance implements ITerminalInstance {
}
return false;
});
}
public attachToElement(container: HTMLElement): void {
if (this._wrapperElement) {
throw new Error('The terminal instance has already been attached to a container');
}
this._container = container;
this._wrapperElement = document.createElement('div');
DOM.addClass(this._wrapperElement, 'terminal-wrapper');
this._xtermElement = document.createElement('div');
this._xterm.open(this._xtermElement);
this._xterm.attachCustomKeydownHandler((event: KeyboardEvent) => {
// Disable all input if the terminal is exiting
if (this._isExiting) {
......@@ -387,9 +394,6 @@ export class TerminalInstance implements ITerminalInstance {
}
private _sendPtyDataToXterm(message: { type: string, content: string }): void {
if (!this._xterm) {
return;
}
if (message.type === 'data') {
this._xterm.write(message.content);
}
......
......@@ -25,6 +25,7 @@ class TestTerminalInstance extends TerminalInstance {
}
protected _createProcess(workspace: IWorkspace, shell: IShellLaunchConfig): void { }
protected _createXterm(): void { }
}
suite('Workbench - TerminalInstance', () => {
......
......@@ -20,7 +20,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
class TestTerminalProcessFactory implements ITerminalProcessFactory {
public create(env: { [key: string]: string }): cp.ChildProcess {
return <any>{};
return <any>{ on: () => { } };
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册