xterm
[VSoRC/.git] / node_modules / xterm / src / browser / renderer / atlas / CharAtlasUtils.ts
1 /**
2  * Copyright (c) 2017 The xterm.js authors. All rights reserved.
3  * @license MIT
4  */
5
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';
10
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,
16     cursor: undefined,
17     cursorAccent: undefined,
18     selection: 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)
22   };
23   return {
24     devicePixelRatio: window.devicePixelRatio,
25     scaledCharWidth,
26     scaledCharHeight,
27     fontFamily: options.fontFamily,
28     fontSize: options.fontSize,
29     fontWeight: options.fontWeight,
30     fontWeightBold: options.fontWeightBold,
31     allowTransparency: options.allowTransparency,
32     colors: clonedColors
33   };
34 }
35
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) {
39       return false;
40     }
41   }
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;
52 }
53
54 export function is256Color(colorCode: number): boolean {
55   return colorCode < DEFAULT_COLOR;
56 }