From d5bc65ec0e7efc88f5b5f4d6a280b680bc136d30 Mon Sep 17 00:00:00 2001 From: Puneethnaik Date: Wed, 3 Jun 2020 19:48:34 +0530 Subject: [PATCH] 1. Removed logic to blend selection with background with 0.3 opacity from ColorManager to a function in color namespace. 2. Changed the DomRenderer and CanvasRenderer where the function defined in color namespace is called. --- src/browser/Color.ts | 13 ++++++++++++- src/browser/ColorManager.ts | 10 ---------- src/browser/renderer/Renderer.ts | 4 ++-- src/browser/renderer/dom/DomRenderer.ts | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/browser/Color.ts b/src/browser/Color.ts index 9649227e..f2ef590f 100644 --- a/src/browser/Color.ts +++ b/src/browser/Color.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { IColor } from 'browser/Types'; +import { IColor, IColorSet } from 'browser/Types'; /** * Helper functions where the source type is "channels" (individual color channels as numbers). @@ -47,6 +47,17 @@ export namespace color { const rgba = channels.toRgba(r, g, b); return { css, rgba }; } + export function blendSelectionWithBgWithOpacity(colors: IColorSet, opacity: number=0.3): void { + const [selectionR, selectionG, selectionB, selectionA] = rgba.toChannels(colors.selection.rgba); + // The selection color is opaque. It needs to be blended with background color at 0.3 opacity Issue #2737 + if (selectionA === 0xFF) { + const newAlpha: number = Math.round(opacity*255); + colors.selection = { + css: channels.toCss(selectionR, selectionG, selectionB, newAlpha), + rgba: channels.toRgba(selectionR, selectionG, selectionB, newAlpha) + }; + } + } export function ensureContrastRatio(bg: IColor, fg: IColor, ratio: number): IColor | undefined { const result = rgba.ensureContrastRatio(bg.rgba, fg.rgba, ratio); diff --git a/src/browser/ColorManager.ts b/src/browser/ColorManager.ts index 057797e9..7d5ad598 100644 --- a/src/browser/ColorManager.ts +++ b/src/browser/ColorManager.ts @@ -116,16 +116,6 @@ export class ColorManager implements IColorManager { this.colors.cursor = this._parseColor(theme.cursor, DEFAULT_CURSOR, true); this.colors.cursorAccent = this._parseColor(theme.cursorAccent, DEFAULT_CURSOR_ACCENT, true); this.colors.selection = this._parseColor(theme.selection, DEFAULT_SELECTION, true); - const [selectionR, selectionG, selectionB, selectionA] = rgba.toChannels(this.colors.selection.rgba); - // The selection color is opaque. It needs to be blended with background color at 0.3 opacity Issue #2737 - if (selectionA === 0xFF) { - const opacity = 0.3; - const newAlpha = Math.round(opacity*255); - this.colors.selection = { - css: channels.toCss(selectionR, selectionG, selectionB, newAlpha), - rgba: channels.toRgba(selectionR, selectionG, selectionB, newAlpha) - }; - } this.colors.selectionOpaque = color.blend(this.colors.background, this.colors.selection); this.colors.ansi[0] = this._parseColor(theme.black, DEFAULT_ANSI_COLORS[0]); this.colors.ansi[1] = this._parseColor(theme.red, DEFAULT_ANSI_COLORS[1]); diff --git a/src/browser/renderer/Renderer.ts b/src/browser/renderer/Renderer.ts index b9f577fe..73b2019a 100644 --- a/src/browser/renderer/Renderer.ts +++ b/src/browser/renderer/Renderer.ts @@ -15,6 +15,7 @@ import { ICharSizeService, ICoreBrowserService } from 'browser/services/Services import { IBufferService, IOptionsService, ICoreService } from 'common/services/Services'; import { removeTerminalFromCache } from 'browser/renderer/atlas/CharAtlasCache'; import { EventEmitter, IEvent } from 'common/EventEmitter'; +import { color } from 'browser/Color'; let nextRendererId = 1; @@ -44,7 +45,7 @@ export class Renderer extends Disposable implements IRenderer { super(); const allowTransparency = this._optionsService.options.allowTransparency; this._characterJoinerRegistry = new CharacterJoinerRegistry(this._bufferService); - + color.blendSelectionWithBgWithOpacity(this._colors); this._renderLayers = [ new TextRenderLayer(this._screenElement, 0, this._colors, this._characterJoinerRegistry, allowTransparency, this._id, this._bufferService, _optionsService), new SelectionRenderLayer(this._screenElement, 1, this._colors, this._id, this._bufferService, _optionsService), @@ -87,7 +88,6 @@ export class Renderer extends Disposable implements IRenderer { public setColors(colors: IColorSet): void { this._colors = colors; - // Clear layers and force a full render this._renderLayers.forEach(l => { l.setColors(this._colors); diff --git a/src/browser/renderer/dom/DomRenderer.ts b/src/browser/renderer/dom/DomRenderer.ts index ff955140..0086f881 100644 --- a/src/browser/renderer/dom/DomRenderer.ts +++ b/src/browser/renderer/dom/DomRenderer.ts @@ -53,7 +53,7 @@ export class DomRenderer extends Disposable implements IRenderer { @IBufferService private readonly _bufferService: IBufferService ) { super(); - + color.blendSelectionWithBgWithOpacity(this._colors); this._rowContainer = document.createElement('div'); this._rowContainer.classList.add(ROW_CONTAINER_CLASS); this._rowContainer.style.lineHeight = 'normal';