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.
This commit is contained in:
Puneethnaik
2020-06-03 19:48:34 +05:30
parent 6daa3f4499
commit d5bc65ec0e
4 changed files with 15 additions and 14 deletions
+12 -1
View File
@@ -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);
-10
View File
@@ -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]);
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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';