diff --git a/packages/plugin-ext/src/main/browser/terminal-main.ts b/packages/plugin-ext/src/main/browser/terminal-main.ts index 5a5cb05d1618c..0ce3146da66c1 100644 --- a/packages/plugin-ext/src/main/browser/terminal-main.ts +++ b/packages/plugin-ext/src/main/browser/terminal-main.ts @@ -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. @@ -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, diff --git a/packages/plugin-ext/src/plugin/terminal-ext.ts b/packages/plugin-ext/src/plugin/terminal-ext.ts index 70e75922faa14..06c37a9a7888f 100644 --- a/packages/plugin-ext/src/plugin/terminal-ext.ts +++ b/packages/plugin-ext/src/plugin/terminal-ext.ts @@ -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. @@ -258,7 +274,6 @@ export class TerminalServiceExtImpl implements TerminalServiceExt { this.setEnvironmentVariableCollection(extensionIdentifier, collection); }); } - } export class EnvironmentVariableCollection implements theia.EnvironmentVariableCollection { diff --git a/packages/plugin/src/theia.d.ts b/packages/plugin/src/theia.d.ts index 1c52a360727c2..c815dbe090446 100644 --- a/packages/plugin/src/theia.d.ts +++ b/packages/plugin/src/theia.d.ts @@ -3005,6 +3005,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; } /** @@ -3067,6 +3080,18 @@ export module '@theia/plugin' { * control it. */ pty: Pseudoterminal; + + /** + * 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; } /** diff --git a/packages/terminal/src/browser/base/terminal-widget.ts b/packages/terminal/src/browser/base/terminal-widget.ts index f1bf943479874..0e3c4831a6b43 100644 --- a/packages/terminal/src/browser/base/terminal-widget.ts +++ b/packages/terminal/src/browser/base/terminal-widget.ts @@ -149,6 +149,11 @@ export interface TerminalWidgetOptions { */ readonly title?: string; + /** + * icon class + */ + readonly iconClass?: string; + /** * Path to the executable shell. For example: `/bin/bash`, `bash`, `sh`. */ diff --git a/packages/terminal/src/browser/terminal-widget-impl.ts b/packages/terminal/src/browser/terminal-widget-impl.ts index 7b0448aab6266..7574f585a619d 100644 --- a/packages/terminal/src/browser/terminal-widget-impl.ts +++ b/packages/terminal/src/browser/terminal-widget-impl.ts @@ -116,7 +116,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;