From c8ccd07d0f70c5bbc2bf5d5c535cd9fbefefb92d Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 1 Apr 2021 12:27:02 -0700 Subject: [PATCH] Add initialText proposed API Part of #120368 --- src/vs/vscode.proposed.d.ts | 13 +++++++++++++ .../api/browser/mainThreadTerminalService.ts | 1 + src/vs/workbench/api/common/extHost.api.impl.ts | 3 +++ src/vs/workbench/api/common/extHost.protocol.ts | 1 + .../workbench/api/common/extHostTerminalService.ts | 3 ++- src/vs/workbench/api/node/extHostTerminalService.ts | 1 + 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index d48a954994b..fe361a2c89d 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -812,6 +812,19 @@ declare module 'vscode' { //#endregion + //#region Terminal initial text https://github.com/microsoft/vscode/issues/120368 + + export interface TerminalOptions { + /** + * Initial text to write to the terminal, note that this is not sent to the process but + * rather written directly to the terminal. This supports escape sequences such a setting + * text style. + */ + readonly initialText?: string; + } + + //#endregion + // eslint-disable-next-line vscode-dts-region-comments //#region @jrieken -> exclusive document filters diff --git a/src/vs/workbench/api/browser/mainThreadTerminalService.ts b/src/vs/workbench/api/browser/mainThreadTerminalService.ts index 75b1d7b857a..9c4d880ceef 100644 --- a/src/vs/workbench/api/browser/mainThreadTerminalService.ts +++ b/src/vs/workbench/api/browser/mainThreadTerminalService.ts @@ -123,6 +123,7 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape executable: launchConfig.shellPath, args: launchConfig.shellArgs, cwd: typeof launchConfig.cwd === 'string' ? launchConfig.cwd : URI.revive(launchConfig.cwd), + initialText: launchConfig.initialText, waitOnExit: launchConfig.waitOnExit, ignoreConfigurationCwd: true, env: launchConfig.env, diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 25a7e4fdb2d..5a69431fd80 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -633,6 +633,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I if ('pty' in nameOrOptions) { return extHostTerminalService.createExtensionTerminal(nameOrOptions); } + if (nameOrOptions.initialText) { + checkProposedApiEnabled(extension); + } return extHostTerminalService.createTerminalFromOptions(nameOrOptions); } return extHostTerminalService.createTerminal(nameOrOptions, shellPath, shellArgs); diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 356eb5c85c1..a1f31aa4a11 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -455,6 +455,7 @@ export interface TerminalLaunchConfig { shellArgs?: string[] | string; cwd?: string | UriComponents; env?: ITerminalEnvironment; + initialText?: string; waitOnExit?: boolean; strictEnv?: boolean; hideFromUser?: boolean; diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index bc6dc84f2a2..a679c8e485e 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -118,6 +118,7 @@ export class ExtHostTerminal { shellArgs?: string[] | string, cwd?: string | URI, env?: ITerminalEnvironment, + initialText?: string, waitOnExit?: boolean, strictEnv?: boolean, hideFromUser?: boolean, @@ -127,7 +128,7 @@ export class ExtHostTerminal { if (typeof this._id !== 'string') { throw new Error('Terminal has already been created'); } - await this._proxy.$createTerminal(this._id, { name: this._name, shellPath, shellArgs, cwd, env, waitOnExit, strictEnv, hideFromUser, isFeatureTerminal, isExtensionOwnedTerminal }); + await this._proxy.$createTerminal(this._id, { name: this._name, shellPath, shellArgs, cwd, env, initialText, waitOnExit, strictEnv, hideFromUser, isFeatureTerminal, isExtensionOwnedTerminal }); } public async createExtensionTerminal(): Promise { diff --git a/src/vs/workbench/api/node/extHostTerminalService.ts b/src/vs/workbench/api/node/extHostTerminalService.ts index 92d2cbd0646..a6c3ec08d68 100644 --- a/src/vs/workbench/api/node/extHostTerminalService.ts +++ b/src/vs/workbench/api/node/extHostTerminalService.ts @@ -65,6 +65,7 @@ export class ExtHostTerminalService extends BaseExtHostTerminalService { withNullAsUndefined(options.shellArgs), withNullAsUndefined(options.cwd), withNullAsUndefined(options.env), + withNullAsUndefined(options.initialText), /*options.waitOnExit*/ undefined, withNullAsUndefined(options.strictEnv), withNullAsUndefined(options.hideFromUser),