diff --git a/packages/plugin-ext/src/plugin/terminal-ext.ts b/packages/plugin-ext/src/plugin/terminal-ext.ts index 4e2873484f141..8d9322b7724d9 100644 --- a/packages/plugin-ext/src/plugin/terminal-ext.ts +++ b/packages/plugin-ext/src/plugin/terminal-ext.ts @@ -76,17 +76,23 @@ export class TerminalServiceExtImpl implements TerminalServiceExt { }; } this.proxy.$createTerminal(id, options, !!pseudoTerminal); - return this.obtainTerminal(id, options.name || 'Terminal'); + + let creationOptions: theia.TerminalOptions | theia.ExtensionTerminalOptions = options; + // make sure to pass ExtensionTerminalOptions as creation options + if (typeof nameOrOptions === 'object' && 'pty' in nameOrOptions) { + creationOptions = nameOrOptions; + } + return this.obtainTerminal(id, options.name || 'Terminal', creationOptions); } attachPtyToTerminal(terminalId: number, pty: theia.Pseudoterminal): void { this._pseudoTerminals.set(terminalId.toString(), new PseudoTerminal(terminalId, this.proxy, pty, true)); } - protected obtainTerminal(id: string, name: string): TerminalExtImpl { + protected obtainTerminal(id: string, name: string, options?: theia.TerminalOptions | theia.ExtensionTerminalOptions): TerminalExtImpl { let terminal = this._terminals.get(id); if (!terminal) { - terminal = new TerminalExtImpl(this.proxy); + terminal = new TerminalExtImpl(this.proxy, options !== undefined ? options : {}); this._terminals.set(id, terminal); } terminal.name = name; @@ -279,7 +285,11 @@ export class TerminalExtImpl implements Terminal { return this.deferredProcessId.promise; } - constructor(private readonly proxy: TerminalServiceMain) { } + readonly creationOptions: Readonly; + + constructor(private readonly proxy: TerminalServiceMain, private readonly options: theia.TerminalOptions | theia.ExtensionTerminalOptions) { + this.creationOptions = this.options; + } sendText(text: string, addNewLine: boolean = true): void { this.id.promise.then(id => this.proxy.$sendText(id, text, addNewLine)); diff --git a/packages/plugin/src/theia.d.ts b/packages/plugin/src/theia.d.ts index 668586bc65c9b..0ab3560fe71cc 100644 --- a/packages/plugin/src/theia.d.ts +++ b/packages/plugin/src/theia.d.ts @@ -2928,6 +2928,12 @@ export module '@theia/plugin' { */ readonly exitStatus: TerminalExitStatus | undefined; + /** + * The object used to initialize the terminal, this is useful for example to detecting the shell type of when the terminal was not launched by this extension or for + * detecting what folder the shell was launched in. + */ + readonly creationOptions: Readonly + /** * Send text to the terminal. * @param text - text content.