提交 6bf0cde9 编写于 作者: D Daniel Imms

Add createTerminal with options API with new option waitOnExit

Fixes #15583
上级 1fafbd08
......@@ -3669,6 +3669,40 @@ declare module 'vscode' {
* @return A new Terminal.
*/
export function createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): Terminal;
/**
* Creates a [Terminal](#Terminal). The cwd of the terminal will be the workspace directory
* if it exists, regardless of whether an explicit customStartPath setting exists.
*
* @param options A TerminalOptions object describing the characteristics of the new terminal.
* @return A new Terminal.
*/
export function createTerminal(options: TerminalOptions): Terminal;
}
/**
* Value-object describing what options formatting should use.
*/
export interface TerminalOptions {
/**
* A human-readable string which will be used to represent the terminal in the UI.
*/
name?: string;
/**
* A path to a custom shell executable to be used in the terminal.
*/
shellPath?: string;
/**
* Args for the custom shell executable, this does not work on Windows (see #8429)
*/
shellArgs?: string[];
/**
* Whether the terminal should wait on exit for a keypress before closing the instance.
*/
waitOnExit?: boolean;
}
/**
......
......@@ -277,7 +277,10 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ
createOutputChannel(name: string): vscode.OutputChannel {
return extHostOutputService.createOutputChannel(name);
},
createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): vscode.Terminal {
createTerminal(nameOrOptions: vscode.TerminalOptions | string, shellPath?: string, shellArgs?: string[]): vscode.Terminal {
if (typeof nameOrOptions === 'object') {
return extHostTerminalService.createTerminalFromOptions(<vscode.TerminalOptions>nameOrOptions);
}
return extHostTerminalService.createTerminal(name, shellPath, shellArgs);
},
// proposed API
......
......@@ -184,7 +184,7 @@ export abstract class MainThreadOutputServiceShape {
}
export abstract class MainThreadTerminalServiceShape {
$createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): TPromise<number> { throw ni(); }
$createTerminal(name?: string, shellPath?: string, shellArgs?: string[], waitOnExit?: boolean): 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(); }
......
......@@ -20,14 +20,20 @@ export class ExtHostTerminal implements vscode.Terminal {
private _pidPromise: TPromise<number>;
private _pidPromiseComplete: TValueCallback<number>;
constructor(proxy: MainThreadTerminalServiceShape, name?: string, shellPath?: string, shellArgs?: string[]) {
constructor(
proxy: MainThreadTerminalServiceShape,
name?: string,
shellPath?: string,
shellArgs?: string[],
waitOnExit?: boolean
) {
this._name = name;
this._queuedRequests = [];
this._proxy = proxy;
this._pidPromise = new TPromise<number>(c => {
this._pidPromiseComplete = c;
});
this._proxy.$createTerminal(name, shellPath, shellArgs).then((id) => {
this._proxy.$createTerminal(name, shellPath, shellArgs, waitOnExit).then((id) => {
this._id = id;
this._queuedRequests.forEach((r) => {
r.run(this._proxy, this._id);
......@@ -107,6 +113,12 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
return terminal;
}
public createTerminalFromOptions(options: vscode.TerminalOptions): vscode.Terminal {
let terminal = new ExtHostTerminal(this._proxy, options.name, options.shellPath, options.shellArgs, options.waitOnExit);
this._terminals.push(terminal);
return terminal;
}
public get onDidCloseTerminal(): Event<vscode.Terminal> {
return this._onDidCloseTerminal && this._onDidCloseTerminal.event;
}
......
......@@ -30,8 +30,8 @@ export class MainThreadTerminalService extends MainThreadTerminalServiceShape {
this._toDispose = dispose(this._toDispose);
}
public $createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): TPromise<number> {
return TPromise.as(this.terminalService.createInstance(name, shellPath, shellArgs, true).id);
public $createTerminal(name?: string, shellPath?: string, shellArgs?: string[], waitOnExit?: boolean): TPromise<number> {
return TPromise.as(this.terminalService.createInstance(name, shellPath, shellArgs, waitOnExit, true).id);
}
public $show(terminalId: number, preserveFocus: boolean): void {
......
......@@ -100,7 +100,7 @@ export interface ITerminalService {
onInstanceTitleChanged: Event<string>;
terminalInstances: ITerminalInstance[];
createInstance(name?: string, shellPath?: string, shellArgs?: string[], ignoreCustomCwd?: boolean): ITerminalInstance;
createInstance(name?: string, shellPath?: string, shellArgs?: string[], waitOnExit?: boolean, ignoreCustomCwd?: boolean): ITerminalInstance;
getInstanceFromId(terminalId: number): ITerminalInstance;
getInstanceLabels(): string[];
getActiveInstance(): ITerminalInstance;
......
......@@ -60,10 +60,11 @@ export class TerminalService implements ITerminalService {
this.onInstanceDisposed((terminalInstance) => { this._removeInstance(terminalInstance); });
}
public createInstance(name?: string, shellPath?: string, shellArgs?: string[], ignoreCustomCwd?: boolean): ITerminalInstance {
public createInstance(name?: string, shellPath?: string, shellArgs?: string[], waitOnExit?: boolean, ignoreCustomCwd?: boolean): ITerminalInstance {
let shell: IShellLaunchConfig = {
executable: shellPath,
args: shellArgs,
waitOnExit,
ignoreCustomCwd
};
let terminalInstance = this._instantiationService.createInstance(TerminalInstance,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册