mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
@@ -153,7 +153,7 @@ export abstract class MainThreadOutputServiceShape {
|
||||
}
|
||||
|
||||
export abstract class MainThreadTerminalServiceShape {
|
||||
$createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): number { throw ni(); }
|
||||
$createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): TPromise<number> { throw ni(); }
|
||||
$dispose(terminalId: number): void { throw ni(); }
|
||||
$hide(terminalId: number): void { throw ni(); }
|
||||
$sendText(terminalId: number, text: string, addNewLine: boolean): void { throw ni(); }
|
||||
|
||||
@@ -10,16 +10,21 @@ import {MainContext, MainThreadTerminalServiceShape} from './extHost.protocol';
|
||||
|
||||
export class ExtHostTerminal implements vscode.Terminal {
|
||||
|
||||
public _name: string;
|
||||
|
||||
private _name: string;
|
||||
private _id: number;
|
||||
private _proxy: MainThreadTerminalServiceShape;
|
||||
private _disposed: boolean;
|
||||
private _queuedRequests: ApiRequest[] = [];
|
||||
|
||||
constructor(proxy: MainThreadTerminalServiceShape, id: number, name?: string, shellPath?: string, shellArgs?: string[]) {
|
||||
constructor(proxy: MainThreadTerminalServiceShape, name?: string, shellPath?: string, shellArgs?: string[]) {
|
||||
this._name = name;
|
||||
this._proxy = proxy;
|
||||
this._id = this._proxy.$createTerminal(name, shellPath, shellArgs);
|
||||
this._proxy.$createTerminal(name, shellPath, shellArgs).then((id) => {
|
||||
this._id = id;
|
||||
this._queuedRequests.forEach((r) => {
|
||||
r.run(this._proxy, this._id);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public get name(): string {
|
||||
@@ -29,26 +34,35 @@ export class ExtHostTerminal implements vscode.Terminal {
|
||||
|
||||
public sendText(text: string, addNewLine: boolean = true): void {
|
||||
this._checkDisposed();
|
||||
this._proxy.$sendText(this._id, text, addNewLine);
|
||||
this._queueApiRequest(this._proxy.$sendText, [text, addNewLine]);
|
||||
}
|
||||
|
||||
public show(preserveFocus: boolean): void {
|
||||
this._checkDisposed();
|
||||
this._proxy.$show(this._id, preserveFocus);
|
||||
this._queueApiRequest(this._proxy.$show, [preserveFocus]);
|
||||
}
|
||||
|
||||
public hide(): void {
|
||||
this._checkDisposed();
|
||||
this._proxy.$hide(this._id);
|
||||
this._queueApiRequest(this._proxy.$hide, []);
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
if (!this._disposed) {
|
||||
this._disposed = true;
|
||||
this._proxy.$dispose(this._id);
|
||||
this._queueApiRequest(this._proxy.$dispose, []);
|
||||
}
|
||||
}
|
||||
|
||||
private _queueApiRequest(callback: (...args: any[]) => void, args: any[]) {
|
||||
let request: ApiRequest = new ApiRequest(callback, args);
|
||||
if (!this._id) {
|
||||
this._queuedRequests.push(request);
|
||||
return;
|
||||
}
|
||||
request.run(this._proxy, this._id);
|
||||
}
|
||||
|
||||
private _checkDisposed() {
|
||||
if (this._disposed) {
|
||||
throw new Error('Terminal has already been disposed');
|
||||
@@ -65,6 +79,20 @@ export class ExtHostTerminalService {
|
||||
}
|
||||
|
||||
public createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): vscode.Terminal {
|
||||
return new ExtHostTerminal(this._proxy, -1, name, shellPath, shellArgs);
|
||||
return new ExtHostTerminal(this._proxy, name, shellPath, shellArgs);
|
||||
}
|
||||
}
|
||||
|
||||
class ApiRequest {
|
||||
private _callback: (...args: any[]) => void;
|
||||
private _args: any[];
|
||||
|
||||
constructor(callback: (...args: any[]) => void, args: any[]) {
|
||||
this._callback = callback;
|
||||
this._args = args;
|
||||
}
|
||||
|
||||
public run(proxy: MainThreadTerminalServiceShape, id: number) {
|
||||
this._callback.apply(proxy, [id].concat(this._args));
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import {ITerminalService} from 'vs/workbench/parts/terminal/electron-browser/ter
|
||||
import {IPanelService} from 'vs/workbench/services/panel/common/panelService';
|
||||
import {IPartService} from 'vs/workbench/services/part/common/partService';
|
||||
import {MainThreadTerminalServiceShape} from './extHost.protocol';
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
|
||||
export class MainThreadTerminalService extends MainThreadTerminalServiceShape {
|
||||
|
||||
@@ -19,8 +20,8 @@ export class MainThreadTerminalService extends MainThreadTerminalServiceShape {
|
||||
super();
|
||||
}
|
||||
|
||||
public $createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): number {
|
||||
return this.terminalService.createInstance(name, shellPath, shellArgs).id;
|
||||
public $createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): TPromise<number> {
|
||||
return TPromise.as(this.terminalService.createInstance(name, shellPath, shellArgs).id);
|
||||
}
|
||||
|
||||
public $show(terminalId: number, preserveFocus: boolean): void {
|
||||
|
||||
Reference in New Issue
Block a user