提交 87b18670 编写于 作者: D Daniel Imms

Get onData listener working

上级 da245253
......@@ -53,11 +53,13 @@ export abstract class TerminalService extends CommonTerminalService implements I
if (shell.runInBackground) {
// TODO: When show is triggered, create a TerminalTab for this instance
// TODO: How do backgrounded terminals interact with extensions listening for them, just ignore?
return this.createInstance(this._terminalFocusContextKey,
const instance = this.createInstance(this._terminalFocusContextKey,
this.configHelper,
undefined,
shell,
true);
this._backgroundedTerminalInstances.push(instance);
return instance;
}
const terminalTab = this._instantiationService.createInstance(TerminalTab,
this._terminalFocusContextKey,
......@@ -77,6 +79,28 @@ export abstract class TerminalService extends CommonTerminalService implements I
return instance;
}
protected _showBackgroundTerminal(instance: ITerminalInstance): void {
// TODO: Remove from _backgroundedTerminalInstances
this._backgroundedTerminalInstances = this._backgroundedTerminalInstances.splice(this._backgroundedTerminalInstances.indexOf(instance), 1);
instance.shellLaunchConfig.runInBackground = false;
console.log('show backgrounded terminal', instance);
const terminalTab = this._instantiationService.createInstance(TerminalTab,
this._terminalFocusContextKey,
this.configHelper,
this._terminalContainer,
instance);
this._terminalTabs.push(terminalTab);
terminalTab.addDisposable(terminalTab.onDisposed(this._onTabDisposed.fire, this._onTabDisposed));
terminalTab.addDisposable(terminalTab.onInstancesChanged(this._onInstancesChanged.fire, this._onInstancesChanged));
this._initInstanceListeners(instance);
if (this.terminalInstances.length === 1) {
// It's the first instance so it should be made active automatically
this.setActiveInstanceByIndex(0);
}
this._onInstancesChanged.fire();
}
public focusFindWidget(): Promise<void> {
return this.showPanel(false).then(() => {
const panel = this._panelService.getActivePanel() as TerminalPanel;
......
......@@ -225,7 +225,7 @@ export class TerminalTab extends Disposable implements ITerminalTab {
terminalFocusContextKey: IContextKey<boolean>,
configHelper: ITerminalConfigHelper,
private _container: HTMLElement,
shellLaunchConfig: IShellLaunchConfig,
shellLaunchConfigOrInstance: IShellLaunchConfig | ITerminalInstance,
@ITerminalService private readonly _terminalService: ITerminalService,
@IWorkbenchLayoutService private readonly _layoutService: IWorkbenchLayoutService
) {
......@@ -233,12 +233,17 @@ export class TerminalTab extends Disposable implements ITerminalTab {
this._onDisposed = new Emitter<ITerminalTab>();
this._onInstancesChanged = new Emitter<void>();
const instance = this._terminalService.createInstance(
terminalFocusContextKey,
configHelper,
undefined,
shellLaunchConfig,
true);
let instance: ITerminalInstance;
if ('id' in shellLaunchConfigOrInstance) {
instance = shellLaunchConfigOrInstance;
} else {
instance = this._terminalService.createInstance(
terminalFocusContextKey,
configHelper,
undefined,
shellLaunchConfigOrInstance,
true);
}
this._terminalInstances.push(instance);
this._initInstanceListeners(instance);
this._activeInstanceIndex = 0;
......
......@@ -30,6 +30,7 @@ export abstract class TerminalService implements ITerminalService {
protected _findWidgetVisible: IContextKey<boolean>;
protected _terminalContainer: HTMLElement;
protected _terminalTabs: ITerminalTab[] = [];
protected _backgroundedTerminalInstances: ITerminalInstance[] = [];
protected get _terminalInstances(): ITerminalInstance[] {
return this._terminalTabs.reduce((p, c) => p.concat(c.terminalInstances), <ITerminalInstance[]>[]);
}
......@@ -103,6 +104,7 @@ export abstract class TerminalService implements ITerminalService {
protected abstract _getWslPath(path: string): Promise<string>;
protected abstract _getWindowsBuildNumber(): number;
protected abstract _showBackgroundTerminal(instance: ITerminalInstance): void;
public abstract refreshActiveTab(): void;
public abstract createTerminal(shell?: IShellLaunchConfig, wasNewTerminalAction?: boolean): ITerminalInstance;
......@@ -222,6 +224,15 @@ export abstract class TerminalService implements ITerminalService {
}
public getInstanceFromId(terminalId: number): ITerminalInstance {
let bgIndex = -1;
this._backgroundedTerminalInstances.forEach((terminalInstance, i) => {
if (terminalInstance.id === terminalId) {
bgIndex = i;
}
});
if (bgIndex !== -1) {
return this._backgroundedTerminalInstances[bgIndex];
}
return this.terminalInstances[this._getIndexFromId(terminalId)];
}
......@@ -230,6 +241,11 @@ export abstract class TerminalService implements ITerminalService {
}
public setActiveInstance(terminalInstance: ITerminalInstance): void {
// If this was a runInBackground terminal created by the API this was triggered by show,
// in which case we need to create the terminal tab
if (terminalInstance.shellLaunchConfig.runInBackground) {
this._showBackgroundTerminal(terminalInstance);
}
this.setActiveInstanceByIndex(this._getIndexFromId(terminalInstance.id));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册