Skip to content

Commit

Permalink
vscode: Support TerminalOptions.hideFromUser
Browse files Browse the repository at this point in the history
* Add TerminalOptions.hideFromUser in theia.d.ts
* Add TerminalWidget.hiddenFromUser
* Fix cwd for created terminals with undefined cwd (default: workspace)

If TerminalOptions.hideFromUser is set to true, the TerminalWidget
will be hidden from any user-facing terminal lists until it is first
explicitly shown to the user (see TerminalWidget.hiddenFromUser).

As we don't open TerminalWidgets by default on `TerminalService.newTerminal`
and as we don't have a global terminal view (in contrast to VS Code),
we only need to hide it in the `TerminalQuickOpenService` really.

Contributed on behalf of STMicroelectronics.
Fixes eclipse-theia#11144

Change-Id: Ic1fdf2d5515d5b2fa8feb58b72218b93eeabda4d
  • Loading branch information
planger committed Oct 13, 2022
1 parent 4b43c7c commit 258ac38
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/main/browser/terminal-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, Disposable
title: options.name,
shellPath: options.shellPath,
shellArgs: options.shellArgs,
cwd: new URI(options.cwd),
cwd: options.cwd ? new URI(options.cwd) : undefined,
env: options.env,
strictEnv: options.strictEnv,
destroyTermOnClose: true,
useServerTitle: false,
attributes: options.attributes,
hideFromUser: options.hideFromUser,
isPseudoTerminal
});
if (options.message) {
Expand Down
9 changes: 9 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,15 @@ export module '@theia/plugin' {
*/
strictEnv?: boolean;

/**
* When enabled the terminal will run the process as normal but not be surfaced to the user
* until `Terminal.show` is called. The typical usage for this is when you need to run
* something that may need interactivity but only want to tell the user about it when
* interaction is needed. Note that the terminals will still be exposed to all extensions
* as normal.
*/
hideFromUser?: boolean;

/**
* A message to write to the terminal on first launch. Note that this is not sent to the
* process, but rather written directly to the terminal. This supports escape sequences such
Expand Down
8 changes: 8 additions & 0 deletions packages/terminal/src/browser/base/terminal-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export abstract class TerminalWidget extends BaseWidget {

abstract readonly exitStatus: TerminalExitStatus | undefined;

/** Terminal widget can be hidden from users until explicitly shown once. */
abstract readonly hiddenFromUser: boolean;

/** The last CWD assigned to the terminal, useful when attempting getCwdURI on a task terminal fails */
lastCwd: URI;

Expand Down Expand Up @@ -202,4 +205,9 @@ export interface TerminalWidgetOptions {
* Terminal kind that indicates whether a terminal is created by a user or by some extension for a user
*/
readonly kind?: 'user' | string;

/**
* When enabled the terminal will run the process as normal but not be surfaced to the user until `Terminal.show` is called.
*/
readonly hideFromUser?: boolean;
}
4 changes: 2 additions & 2 deletions packages/terminal/src/browser/terminal-quick-open-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export class TerminalQuickOpenService implements QuickAccessProvider {
async getPicks(filter: string, token: CancellationToken): Promise<QuickPicks> {
const items: QuickPickItem[] = [];

// Get the sorted list of currently opened terminal widgets
const widgets: TerminalWidget[] = this.terminalService.all
// Get the sorted list of currently opened terminal widgets that aren't hidden from users
const widgets: TerminalWidget[] = this.terminalService.all.filter(widget => !widget.hiddenFromUser)
.sort((a: TerminalWidget, b: TerminalWidget) => this.compareItems(a, b));

for (const widget of widgets) {
Expand Down
9 changes: 9 additions & 0 deletions packages/terminal/src/browser/terminal-widget-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
protected hoverMessage: HTMLDivElement;
protected lastTouchEnd: TouchEvent | undefined;
protected isAttachedCloseListener: boolean = false;
protected shown = false;
override lastCwd = new URI();

@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
Expand Down Expand Up @@ -349,6 +350,13 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
return this.lastTouchEnd;
}

get hiddenFromUser(): boolean {
if (this.shown) {
return false;
}
return this.options.hideFromUser ?? false;
}

onDispose(onDispose: () => void): void {
this.toDispose.push(Disposable.create(onDispose));
}
Expand Down Expand Up @@ -461,6 +469,7 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
protected override onAfterShow(msg: Message): void {
super.onAfterShow(msg);
this.update();
this.shown = true;
}
protected override onAfterAttach(msg: Message): void {
Widget.attach(this.searchBox, this.node);
Expand Down

0 comments on commit 258ac38

Please sign in to comment.