Skip to content
13 changes: 12 additions & 1 deletion src/browser/Color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/browser/ColorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { IColorManager, IColor, IColorSet, IColorContrastCache } from 'browser/Types';
import { ITheme } from 'common/services/Services';
import { channels, color, css } from 'browser/Color';
import { channels, color, css, rgba } from 'browser/Color';
import { ColorContrastCache } from 'browser/ColorContrastCache';

const DEFAULT_FOREGROUND = css.toColor('#ffffff');
Expand Down
4 changes: 2 additions & 2 deletions src/browser/renderer/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -89,7 +90,6 @@ export class Renderer extends Disposable implements IRenderer {

public setColors(colors: IColorSet): void {
this._colors = colors;

// Clear layers and force a full render
for (const l of this._renderLayers) {
l.setColors(this._colors);
Expand Down
2 changes: 1 addition & 1 deletion src/browser/renderer/dom/DomRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,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';
Expand Down