Skip to content

Commit 9e5db77

Browse files
committed
[vscode] Support Terminal#creationOptions #11138
Signed-off-by: Johannes Faltermeier <[email protected]> Co-authored-by: Vincent Fugnitto <[email protected]> Contributed on behalf of STMicroelectronics
1 parent af83aaa commit 9e5db77

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

packages/plugin-ext/src/plugin/terminal-ext.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,23 @@ export class TerminalServiceExtImpl implements TerminalServiceExt {
7676
};
7777
}
7878
this.proxy.$createTerminal(id, options, !!pseudoTerminal);
79-
return this.obtainTerminal(id, options.name || 'Terminal');
79+
80+
let creationOptions: theia.TerminalOptions | theia.ExtensionTerminalOptions = options;
81+
// make sure to pass ExtensionTerminalOptions as creation options
82+
if (typeof nameOrOptions === 'object' && 'pty' in nameOrOptions) {
83+
creationOptions = nameOrOptions;
84+
}
85+
return this.obtainTerminal(id, options.name || 'Terminal', creationOptions);
8086
}
8187

8288
attachPtyToTerminal(terminalId: number, pty: theia.Pseudoterminal): void {
8389
this._pseudoTerminals.set(terminalId.toString(), new PseudoTerminal(terminalId, this.proxy, pty, true));
8490
}
8591

86-
protected obtainTerminal(id: string, name: string): TerminalExtImpl {
92+
protected obtainTerminal(id: string, name: string, options?: theia.TerminalOptions | theia.ExtensionTerminalOptions): TerminalExtImpl {
8793
let terminal = this._terminals.get(id);
8894
if (!terminal) {
89-
terminal = new TerminalExtImpl(this.proxy);
95+
terminal = new TerminalExtImpl(this.proxy, options ?? {});
9096
this._terminals.set(id, terminal);
9197
}
9298
terminal.name = name;
@@ -279,7 +285,11 @@ export class TerminalExtImpl implements Terminal {
279285
return this.deferredProcessId.promise;
280286
}
281287

282-
constructor(private readonly proxy: TerminalServiceMain) { }
288+
readonly creationOptions: Readonly<TerminalOptions | ExtensionTerminalOptions>;
289+
290+
constructor(private readonly proxy: TerminalServiceMain, private readonly options: theia.TerminalOptions | theia.ExtensionTerminalOptions) {
291+
this.creationOptions = this.options;
292+
}
283293

284294
sendText(text: string, addNewLine: boolean = true): void {
285295
this.id.promise.then(id => this.proxy.$sendText(id, text, addNewLine));

packages/plugin/src/theia.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -2928,6 +2928,12 @@ export module '@theia/plugin' {
29282928
*/
29292929
readonly exitStatus: TerminalExitStatus | undefined;
29302930

2931+
/**
2932+
* 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
2933+
* detecting what folder the shell was launched in.
2934+
*/
2935+
readonly creationOptions: Readonly<TerminalOptions | ExtensionTerminalOptions>
2936+
29312937
/**
29322938
* Send text to the terminal.
29332939
* @param text - text content.

0 commit comments

Comments
 (0)