2 * Copyright (c) 2017 The xterm.js authors. All rights reserved.
6 import { ICharAtlasConfig } from 'browser/renderer/atlas/Types';
7 import { DEFAULT_COLOR } from 'common/buffer/Constants';
8 import { IColorSet, IPartialColorSet } from 'browser/Types';
9 import { ITerminalOptions } from 'common/services/Services';
11 export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, options: ITerminalOptions, colors: IColorSet): ICharAtlasConfig {
12 // null out some fields that don't matter
13 const clonedColors = <IPartialColorSet>{
14 foreground: colors.foreground,
15 background: colors.background,
17 cursorAccent: undefined,
19 // For the static char atlas, we only use the first 16 colors, but we need all 256 for the
20 // dynamic character atlas.
21 ansi: colors.ansi.slice(0, 16)
24 devicePixelRatio: window.devicePixelRatio,
27 fontFamily: options.fontFamily,
28 fontSize: options.fontSize,
29 fontWeight: options.fontWeight,
30 fontWeightBold: options.fontWeightBold,
31 allowTransparency: options.allowTransparency,
36 export function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean {
37 for (let i = 0; i < a.colors.ansi.length; i++) {
38 if (a.colors.ansi[i].rgba !== b.colors.ansi[i].rgba) {
42 return a.devicePixelRatio === b.devicePixelRatio &&
43 a.fontFamily === b.fontFamily &&
44 a.fontSize === b.fontSize &&
45 a.fontWeight === b.fontWeight &&
46 a.fontWeightBold === b.fontWeightBold &&
47 a.allowTransparency === b.allowTransparency &&
48 a.scaledCharWidth === b.scaledCharWidth &&
49 a.scaledCharHeight === b.scaledCharHeight &&
50 a.colors.foreground === b.colors.foreground &&
51 a.colors.background === b.colors.background;
54 export function is256Color(colorCode: number): boolean {
55 return colorCode < DEFAULT_COLOR;