Skip to content

Commit

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

Fixes #11504
  • Loading branch information
rschnekenbu authored Jan 12, 2023
1 parent 911c0ca commit 315f2e0
Show file tree
Hide file tree
Showing 5 changed files with 57 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
20 changes: 18 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 | theia.ExtensionTerminalOptions): 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 @@ -65,7 +81,7 @@ export class TerminalServiceExtImpl implements TerminalServiceExt {
nameOrOptions: TerminalOptions | PseudoTerminalOptions | ExtensionTerminalOptions | (string | undefined),
shellPath?: string, shellArgs?: string[] | string
): Terminal {
let options: TerminalOptions;
let options: TerminalOptions | ExtensionTerminalOptions;
let pseudoTerminal: theia.Pseudoterminal | undefined = undefined;
const id = `plugin-terminal-${UUID.uuid4()}`;
if (typeof nameOrOptions === 'object') {
Expand Down
26 changes: 26 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3016,6 +3016,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?: 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 @@ -3089,6 +3102,19 @@ export module '@theia/plugin' {
* This will only take effect when `terminal.integrated.enablePersistentSessions` is enabled.
*/
isTransient?: boolean;

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

/**
* The icon {@link ThemeColor} for the terminal.
* The standard `terminal.ansi*` theme keys are
* recommended for the best contrast and consistency across themes.
* @stubbed
*/
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 315f2e0

Please sign in to comment.