Skip to content

Commit

Permalink
wip - vscode: Support optional iconPath and color
Browse files Browse the repository at this point in the history
in TerminalOptions and ExtensionTerminalOptions
Contributed on behalf of STMicroelectronics

Fixes eclipse-theia#11504
  • Loading branch information
rschnekenbu committed Jan 10, 2023
1 parent 92e9581 commit 65a3d49
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/plugin-ext/src/main/browser/terminal-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { SerializableEnvironmentVariableCollection } from '@theia/terminal/lib/c
import { ShellTerminalServerProxy } from '@theia/terminal/lib/common/shell-terminal-protocol';
import { TerminalLink, TerminalLinkProvider } from '@theia/terminal/lib/browser/terminal-link-provider';
import { URI } from '@theia/core/lib/common/uri';
import { getIconClass } from '../../plugin/terminal-ext';

/**
* Plugin api service allows working with terminal emulator.
Expand Down Expand Up @@ -127,6 +128,7 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, TerminalLin
const terminal = await this.terminals.newTerminal({
id,
title: options.name,
iconClass: getIconClass(options),
shellPath: options.shellPath,
shellArgs: options.shellArgs,
cwd: options.cwd ? new URI(options.cwd) : undefined,
Expand Down
19 changes: 17 additions & 2 deletions packages/plugin-ext/src/plugin/terminal-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,25 @@ import { RPCProtocol } from '../common/rpc-protocol';
import { Event, Emitter } from '@theia/core/lib/common/event';
import { Deferred } from '@theia/core/lib/common/promise-util';
import * as theia from '@theia/plugin';
import { Disposable, EnvironmentVariableMutatorType } from './types-impl';
import { Disposable, EnvironmentVariableMutatorType, ThemeIcon } from './types-impl';
import { SerializableEnvironmentVariableCollection } from '@theia/terminal/lib/common/base-terminal-protocol';
import { ProvidedTerminalLink } from '../common/plugin-api-rpc-model';
import { ThemeIcon as MonacoThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';

export function getIconUris(iconPath: theia.TerminalOptions['iconPath']): { id: string } | undefined {
if (ThemeIcon.is(iconPath)) {
return { id: iconPath.id };
}
return undefined;
}

export function getIconClass(options: theia.TerminalOptions): string | undefined {
const iconClass = getIconUris(options.iconPath);
if (iconClass) {
return MonacoThemeIcon.asClassName(iconClass);
}
return undefined;
}

/**
* Provides high level terminal plugin api to use in the Theia plugins.
Expand Down Expand Up @@ -273,7 +289,6 @@ export class TerminalServiceExtImpl implements TerminalServiceExt {
this.setEnvironmentVariableCollection(extensionIdentifier, collection);
});
}

}

export class EnvironmentVariableCollection implements theia.EnvironmentVariableCollection {
Expand Down
25 changes: 25 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3010,6 +3010,19 @@ export module '@theia/plugin' {
* Terminal attributes. Can be useful to apply some implementation specific information.
*/
attributes?: { [key: string]: string | null };

/**
* The icon path or {@link ThemeIcon} for the terminal.
*/
iconPath?: Uri | { light: Uri; dark: Uri } | ThemeIcon;

/**
* The icon {@link ThemeColor} for the terminal.
* The `terminal.ansi*` theme keys are
* recommended for the best contrast and consistency across themes.
* @stubbed
*/
color?: ThemeColor;
}

/**
Expand Down Expand Up @@ -3077,6 +3090,18 @@ export module '@theia/plugin' {
* The {@link TerminalLocation} or {@link TerminalEditorLocationOptions} or {@link TerminalSplitLocationOptions} for the terminal.
*/
location?: TerminalLocation | TerminalEditorLocationOptions | TerminalSplitLocationOptions;

/**
* The icon path or {@link ThemeIcon} for the terminal.
*/
iconPath?: Uri | { light: Uri; dark: Uri } | ThemeIcon;

/**
* The icon {@link ThemeColor} for the terminal.
* The standard `terminal.ansi*` theme keys are
* recommended for the best contrast and consistency across themes.
*/
color?: ThemeColor;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/terminal/src/browser/base/terminal-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ export interface TerminalWidgetOptions {
*/
readonly title?: string;

/**
* icon class
*/
readonly iconClass?: string;

/**
* Path to the executable shell. For example: `/bin/bash`, `bash`, `sh`.
*/
Expand Down
7 changes: 6 additions & 1 deletion packages/terminal/src/browser/terminal-widget-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
@postConstruct()
protected init(): void {
this.setTitle(this.options.title || TerminalWidgetImpl.LABEL);
this.title.iconClass = codicon('terminal');

if (this.options.iconClass) {
this.title.iconClass = this.options.iconClass;
} else {
this.title.iconClass = codicon('terminal');
}

if (this.options.kind) {
this.terminalKind = this.options.kind;
Expand Down

0 comments on commit 65a3d49

Please sign in to comment.