This mostly worked before, but clearColor made the assumption that the colors were always in #RRBBGG format. See the discussion here: https://github.com/xtermjs/xterm.js/pull/1327#issuecomment-374812842 This changes the internal representation of a color so that we hold onto into an object containing the original css string along with an RGBA value encoded as a 32-bit uint. clearColor can then use that RGBA representation. Additionally, this deduplicates some code between ColorManager and Terminal. Terminal was generating the 256 ansi colors the same way ColorManager was, so this just makes Terminal use the same constant.
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
/**
|
|
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
|
* @license MIT
|
|
*/
|
|
|
|
import { ITerminal } from '../../Types';
|
|
import { IColorSet } from '../Types';
|
|
import { ICharAtlasConfig } from '../../shared/atlas/Types';
|
|
|
|
export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, terminal: ITerminal, colors: IColorSet): ICharAtlasConfig {
|
|
const clonedColors = {
|
|
foreground: colors.foreground,
|
|
background: colors.background,
|
|
cursor: null,
|
|
cursorAccent: null,
|
|
selection: null,
|
|
ansi: colors.ansi.slice(0, 16)
|
|
};
|
|
return {
|
|
devicePixelRatio: window.devicePixelRatio,
|
|
scaledCharWidth,
|
|
scaledCharHeight,
|
|
fontFamily: terminal.options.fontFamily,
|
|
fontSize: terminal.options.fontSize,
|
|
fontWeight: terminal.options.fontWeight,
|
|
fontWeightBold: terminal.options.fontWeightBold,
|
|
allowTransparency: terminal.options.allowTransparency,
|
|
colors: clonedColors
|
|
};
|
|
}
|
|
|
|
export function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean {
|
|
for (let i = 0; i < a.colors.ansi.length; i++) {
|
|
if (a.colors.ansi[i].rgba !== b.colors.ansi[i].rgba) {
|
|
return false;
|
|
}
|
|
}
|
|
return a.devicePixelRatio === b.devicePixelRatio &&
|
|
a.fontFamily === b.fontFamily &&
|
|
a.fontSize === b.fontSize &&
|
|
a.fontWeight === b.fontWeight &&
|
|
a.fontWeightBold === b.fontWeightBold &&
|
|
a.allowTransparency === b.allowTransparency &&
|
|
a.scaledCharWidth === b.scaledCharWidth &&
|
|
a.scaledCharHeight === b.scaledCharHeight &&
|
|
a.colors.foreground === b.colors.foreground &&
|
|
a.colors.background === b.colors.background;
|
|
}
|