From c5022723731c503d7862758a8c846e397babaeb2 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 16 May 2022 09:40:07 -0700 Subject: [PATCH] Support selection foreground in webgl Part of #3810 --- addons/xterm-addon-webgl/src/WebglRenderer.ts | 3 +++ addons/xterm-addon-webgl/src/atlas/CharAtlasUtils.ts | 1 + src/browser/ColorManager.ts | 10 ++++++++++ src/browser/Types.d.ts | 1 + src/common/services/Services.ts | 1 + typings/xterm.d.ts | 2 ++ 6 files changed, 18 insertions(+) diff --git a/addons/xterm-addon-webgl/src/WebglRenderer.ts b/addons/xterm-addon-webgl/src/WebglRenderer.ts index d060c4d1..dbe9da91 100644 --- a/addons/xterm-addon-webgl/src/WebglRenderer.ts +++ b/addons/xterm-addon-webgl/src/WebglRenderer.ts @@ -398,6 +398,9 @@ export class WebglRenderer extends Disposable implements IRenderer { // Apply the selection color if needed if (this._isCellSelected(x, y)) { bgOverride = this._colors.selectionOpaque.rgba >> 8 & 0xFFFFFF; + if (this._colors.selectionForeground) { + fgOverride = this._colors.selectionForeground.rgba >> 8 && 0xFFFFFF; + } } // Apply decorations on the top layer diff --git a/addons/xterm-addon-webgl/src/atlas/CharAtlasUtils.ts b/addons/xterm-addon-webgl/src/atlas/CharAtlasUtils.ts index 0ce893df..92cfd4a9 100644 --- a/addons/xterm-addon-webgl/src/atlas/CharAtlasUtils.ts +++ b/addons/xterm-addon-webgl/src/atlas/CharAtlasUtils.ts @@ -23,6 +23,7 @@ export function generateConfig(scaledCellWidth: number, scaledCellHeight: number cursorAccent: NULL_COLOR, selectionTransparent: NULL_COLOR, selectionOpaque: NULL_COLOR, + selectionForeground: NULL_COLOR, // For the static char atlas, we only use the first 16 colors, but we need all 256 for the // dynamic character atlas. ansi: colors.ansi.slice(), diff --git a/src/browser/ColorManager.ts b/src/browser/ColorManager.ts index 2d6e4ea5..f11ef8fd 100644 --- a/src/browser/ColorManager.ts +++ b/src/browser/ColorManager.ts @@ -104,6 +104,7 @@ export class ColorManager implements IColorManager { cursorAccent: DEFAULT_CURSOR_ACCENT, selectionTransparent: DEFAULT_SELECTION, selectionOpaque: color.blend(DEFAULT_BACKGROUND, DEFAULT_SELECTION), + selectionForeground: undefined, ansi: DEFAULT_ANSI_COLORS.slice(), contrastCache: this._contrastCache }; @@ -128,6 +129,15 @@ export class ColorManager implements IColorManager { this.colors.cursorAccent = this._parseColor(theme.cursorAccent, DEFAULT_CURSOR_ACCENT, true); this.colors.selectionTransparent = this._parseColor(theme.selection, DEFAULT_SELECTION, true); this.colors.selectionOpaque = color.blend(this.colors.background, this.colors.selectionTransparent); + const nullColor: IColor = { + css: '', + rgba: 0 + }; + this.colors.selectionForeground = theme.selectionForeground ? this._parseColor(theme.selectionForeground, nullColor) : undefined; + if (this.colors.selectionForeground === nullColor) { + this.colors.selectionForeground = undefined; + } + /** * If selection color is opaque, blend it with background with 0.3 opacity * Issue #2737 diff --git a/src/browser/Types.d.ts b/src/browser/Types.d.ts index 0e83c213..129842d5 100644 --- a/src/browser/Types.d.ts +++ b/src/browser/Types.d.ts @@ -120,6 +120,7 @@ export interface IColorSet { selectionTransparent: IColor; /** The selection blended on top of background. */ selectionOpaque: IColor; + selectionForeground: IColor | undefined; ansi: IColor[]; contrastCache: IColorContrastCache; } diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index c3190210..017eb386 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -259,6 +259,7 @@ export interface ITheme { cursor?: string; cursorAccent?: string; selection?: string; + selectionForeground?: string; black?: string; red?: string; green?: string; diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 15ee4650..ce6c8d3f 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -288,6 +288,8 @@ declare module 'xterm' { cursorAccent?: string; /** The selection background color (can be transparent) */ selection?: string; + /** The selection foreground color */ + selectionForeground?: string; /** ANSI black (eg. `\x1b[30m`) */ black?: string; /** ANSI red (eg. `\x1b[31m`) */