Skip to content

Commit

Permalink
[vscode] Support Terminal#creationOptions #11138
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Faltermeier <[email protected]>
Co-authored-by: Vincent Fugnitto <[email protected]>

Contributed on behalf of STMicroelectronics
  • Loading branch information
jfaltermeier committed Sep 1, 2022
1 parent af83aaa commit 9e5db77
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/plugin-ext/src/plugin/terminal-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? {});
this._terminals.set(id, terminal);
}
terminal.name = name;
Expand Down Expand Up @@ -279,7 +285,11 @@ export class TerminalExtImpl implements Terminal {
return this.deferredProcessId.promise;
}

constructor(private readonly proxy: TerminalServiceMain) { }
readonly creationOptions: Readonly<TerminalOptions | ExtensionTerminalOptions>;

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));
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TerminalOptions | ExtensionTerminalOptions>

/**
* Send text to the terminal.
* @param text - text content.
Expand Down

0 comments on commit 9e5db77

Please sign in to comment.