@xterm/xterm 5.6.0-beta.91 → 5.6.0-beta.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/xterm.js +1 -1
- package/lib/xterm.js.map +1 -1
- package/lib/xterm.mjs +13 -13
- package/lib/xterm.mjs.map +4 -4
- package/package.json +2 -2
- package/src/browser/renderer/shared/Constants.ts +0 -8
- package/src/browser/renderer/shared/Types.ts +2 -92
- package/src/browser/renderer/shared/CellColorResolver.ts +0 -236
- package/src/browser/renderer/shared/CharAtlasCache.ts +0 -97
- package/src/browser/renderer/shared/CharAtlasUtils.ts +0 -80
- package/src/browser/renderer/shared/CursorBlinkStateManager.ts +0 -146
- package/src/browser/renderer/shared/CustomGlyphs.ts +0 -693
- package/src/browser/renderer/shared/DevicePixelObserver.ts +0 -40
- package/src/browser/renderer/shared/TextureAtlas.ts +0 -1133
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xterm/xterm",
|
|
3
3
|
"description": "Full xterm terminal, in your browser",
|
|
4
|
-
"version": "5.6.0-beta.
|
|
4
|
+
"version": "5.6.0-beta.93",
|
|
5
5
|
"main": "lib/xterm.js",
|
|
6
6
|
"module": "lib/xterm.mjs",
|
|
7
7
|
"style": "css/xterm.css",
|
|
@@ -107,5 +107,5 @@
|
|
|
107
107
|
"ws": "^8.2.3",
|
|
108
108
|
"xterm-benchmark": "^0.3.1"
|
|
109
109
|
},
|
|
110
|
-
"commit": "
|
|
110
|
+
"commit": "0692d486f40ac8cc74d57444cb0525d987dc011c"
|
|
111
111
|
}
|
|
@@ -3,12 +3,4 @@
|
|
|
3
3
|
* @license MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { isFirefox, isLegacyEdge } from 'common/Platform';
|
|
7
|
-
|
|
8
6
|
export const INVERTED_DEFAULT_COLOR = 257;
|
|
9
|
-
|
|
10
|
-
export const DIM_OPACITY = 0.5;
|
|
11
|
-
// The text baseline is set conditionally by browser. Using 'ideographic' for Firefox or Legacy Edge
|
|
12
|
-
// would result in truncated text (Issue 3353). Using 'bottom' for Chrome would result in slightly
|
|
13
|
-
// unaligned Powerline fonts (PR 3356#issuecomment-850928179).
|
|
14
|
-
export const TEXT_BASELINE: CanvasTextBaseline = isFirefox || isLegacyEdge ? 'bottom' : 'ideographic';
|
|
@@ -3,31 +3,11 @@
|
|
|
3
3
|
* @license MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { Terminal } from '@xterm/xterm';
|
|
7
|
+
import { ITerminal } from 'browser/Types';
|
|
8
8
|
import { IDisposable } from 'common/Types';
|
|
9
9
|
import type { Event } from 'vs/base/common/event';
|
|
10
10
|
|
|
11
|
-
export interface ICharAtlasConfig {
|
|
12
|
-
customGlyphs: boolean;
|
|
13
|
-
devicePixelRatio: number;
|
|
14
|
-
deviceMaxTextureSize: number;
|
|
15
|
-
letterSpacing: number;
|
|
16
|
-
lineHeight: number;
|
|
17
|
-
fontSize: number;
|
|
18
|
-
fontFamily: string;
|
|
19
|
-
fontWeight: FontWeight;
|
|
20
|
-
fontWeightBold: FontWeight;
|
|
21
|
-
deviceCellWidth: number;
|
|
22
|
-
deviceCellHeight: number;
|
|
23
|
-
deviceCharWidth: number;
|
|
24
|
-
deviceCharHeight: number;
|
|
25
|
-
allowTransparency: boolean;
|
|
26
|
-
drawBoldTextInBrightColors: boolean;
|
|
27
|
-
minimumContrastRatio: number;
|
|
28
|
-
colors: IColorSet;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
11
|
export interface IDimensions {
|
|
32
12
|
width: number;
|
|
33
13
|
height: number;
|
|
@@ -87,76 +67,6 @@ export interface IRenderer extends IDisposable {
|
|
|
87
67
|
clearTextureAtlas?(): void;
|
|
88
68
|
}
|
|
89
69
|
|
|
90
|
-
export interface ITextureAtlas extends IDisposable {
|
|
91
|
-
readonly pages: { canvas: HTMLCanvasElement, version: number }[];
|
|
92
|
-
|
|
93
|
-
onAddTextureAtlasCanvas: Event<HTMLCanvasElement>;
|
|
94
|
-
onRemoveTextureAtlasCanvas: Event<HTMLCanvasElement>;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Warm up the texture atlas, adding common glyphs to avoid slowing early frame.
|
|
98
|
-
*/
|
|
99
|
-
warmUp(): void;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Call when a frame is being drawn, this will return true if the atlas was cleared to make room
|
|
103
|
-
* for a new set of glyphs.
|
|
104
|
-
*/
|
|
105
|
-
beginFrame(): boolean;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Clear all glyphs from the texture atlas.
|
|
109
|
-
*/
|
|
110
|
-
clearTexture(): void;
|
|
111
|
-
getRasterizedGlyph(code: number, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph;
|
|
112
|
-
getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Represents a rasterized glyph within a texture atlas. Some numbers are
|
|
117
|
-
* tracked in CSS pixels as well in order to reduce calculations during the
|
|
118
|
-
* render loop.
|
|
119
|
-
*/
|
|
120
|
-
export interface IRasterizedGlyph {
|
|
121
|
-
/**
|
|
122
|
-
* The x and y offset between the glyph's top/left and the top/left of a cell
|
|
123
|
-
* in pixels.
|
|
124
|
-
*/
|
|
125
|
-
offset: IVector;
|
|
126
|
-
/**
|
|
127
|
-
* The index of the texture page that the glyph is on.
|
|
128
|
-
*/
|
|
129
|
-
texturePage: number;
|
|
130
|
-
/**
|
|
131
|
-
* the x and y position of the glyph in the texture in pixels.
|
|
132
|
-
*/
|
|
133
|
-
texturePosition: IVector;
|
|
134
|
-
/**
|
|
135
|
-
* the x and y position of the glyph in the texture in clip space coordinates.
|
|
136
|
-
*/
|
|
137
|
-
texturePositionClipSpace: IVector;
|
|
138
|
-
/**
|
|
139
|
-
* The width and height of the glyph in the texture in pixels.
|
|
140
|
-
*/
|
|
141
|
-
size: IVector;
|
|
142
|
-
/**
|
|
143
|
-
* The width and height of the glyph in the texture in clip space coordinates.
|
|
144
|
-
*/
|
|
145
|
-
sizeClipSpace: IVector;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export interface IVector {
|
|
149
|
-
x: number;
|
|
150
|
-
y: number;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export interface IBoundingBox {
|
|
154
|
-
top: number;
|
|
155
|
-
left: number;
|
|
156
|
-
right: number;
|
|
157
|
-
bottom: number;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
70
|
export interface ISelectionRenderModel {
|
|
161
71
|
readonly hasSelection: boolean;
|
|
162
72
|
readonly columnSelectMode: boolean;
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { ISelectionRenderModel } from 'browser/renderer/shared/Types';
|
|
2
|
-
import { ICoreBrowserService, IThemeService } from 'browser/services/Services';
|
|
3
|
-
import { ReadonlyColorSet } from 'browser/Types';
|
|
4
|
-
import { Attributes, BgFlags, ExtFlags, FgFlags, NULL_CELL_CODE, UnderlineStyle } from 'common/buffer/Constants';
|
|
5
|
-
import { IDecorationService, IOptionsService } from 'common/services/Services';
|
|
6
|
-
import { ICellData } from 'common/Types';
|
|
7
|
-
import { Terminal } from '@xterm/xterm';
|
|
8
|
-
import { rgba } from 'common/Color';
|
|
9
|
-
import { treatGlyphAsBackgroundColor } from 'browser/renderer/shared/RendererUtils';
|
|
10
|
-
|
|
11
|
-
// Work variables to avoid garbage collection
|
|
12
|
-
let $fg = 0;
|
|
13
|
-
let $bg = 0;
|
|
14
|
-
let $hasFg = false;
|
|
15
|
-
let $hasBg = false;
|
|
16
|
-
let $isSelected = false;
|
|
17
|
-
let $colors: ReadonlyColorSet | undefined;
|
|
18
|
-
let $variantOffset = 0;
|
|
19
|
-
|
|
20
|
-
export class CellColorResolver {
|
|
21
|
-
/**
|
|
22
|
-
* The shared result of the {@link resolve} call. This is only safe to use immediately after as
|
|
23
|
-
* any other calls will share object.
|
|
24
|
-
*/
|
|
25
|
-
public readonly result: { fg: number, bg: number, ext: number } = {
|
|
26
|
-
fg: 0,
|
|
27
|
-
bg: 0,
|
|
28
|
-
ext: 0
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
private readonly _terminal: Terminal,
|
|
33
|
-
private readonly _optionService: IOptionsService,
|
|
34
|
-
private readonly _selectionRenderModel: ISelectionRenderModel,
|
|
35
|
-
private readonly _decorationService: IDecorationService,
|
|
36
|
-
private readonly _coreBrowserService: ICoreBrowserService,
|
|
37
|
-
private readonly _themeService: IThemeService
|
|
38
|
-
) {
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Resolves colors for the cell, putting the result into the shared {@link result}. This resolves
|
|
43
|
-
* overrides, inverse and selection for the cell which can then be used to feed into the renderer.
|
|
44
|
-
*/
|
|
45
|
-
public resolve(cell: ICellData, x: number, y: number, deviceCellWidth: number): void {
|
|
46
|
-
this.result.bg = cell.bg;
|
|
47
|
-
this.result.fg = cell.fg;
|
|
48
|
-
this.result.ext = cell.bg & BgFlags.HAS_EXTENDED ? cell.extended.ext : 0;
|
|
49
|
-
// Get any foreground/background overrides, this happens on the model to avoid spreading
|
|
50
|
-
// override logic throughout the different sub-renderers
|
|
51
|
-
|
|
52
|
-
// Reset overrides work variables
|
|
53
|
-
$bg = 0;
|
|
54
|
-
$fg = 0;
|
|
55
|
-
$hasBg = false;
|
|
56
|
-
$hasFg = false;
|
|
57
|
-
$isSelected = false;
|
|
58
|
-
$colors = this._themeService.colors;
|
|
59
|
-
$variantOffset = 0;
|
|
60
|
-
|
|
61
|
-
const code = cell.getCode();
|
|
62
|
-
if (code !== NULL_CELL_CODE && cell.extended.underlineStyle === UnderlineStyle.DOTTED) {
|
|
63
|
-
const lineWidth = Math.max(1, Math.floor(this._optionService.rawOptions.fontSize * this._coreBrowserService.dpr / 15));
|
|
64
|
-
$variantOffset = x * deviceCellWidth % (Math.round(lineWidth) * 2);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Apply decorations on the bottom layer
|
|
68
|
-
this._decorationService.forEachDecorationAtCell(x, y, 'bottom', d => {
|
|
69
|
-
if (d.backgroundColorRGB) {
|
|
70
|
-
$bg = d.backgroundColorRGB.rgba >> 8 & Attributes.RGB_MASK;
|
|
71
|
-
$hasBg = true;
|
|
72
|
-
}
|
|
73
|
-
if (d.foregroundColorRGB) {
|
|
74
|
-
$fg = d.foregroundColorRGB.rgba >> 8 & Attributes.RGB_MASK;
|
|
75
|
-
$hasFg = true;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// Apply the selection color if needed
|
|
80
|
-
$isSelected = this._selectionRenderModel.isCellSelected(this._terminal, x, y);
|
|
81
|
-
if ($isSelected) {
|
|
82
|
-
// If the cell has a bg color, retain the color by blending it with the selection color
|
|
83
|
-
if (
|
|
84
|
-
(this.result.fg & FgFlags.INVERSE) ||
|
|
85
|
-
(this.result.bg & Attributes.CM_MASK) !== Attributes.CM_DEFAULT
|
|
86
|
-
) {
|
|
87
|
-
// Resolve the standard bg color
|
|
88
|
-
if (this.result.fg & FgFlags.INVERSE) {
|
|
89
|
-
switch (this.result.fg & Attributes.CM_MASK) {
|
|
90
|
-
case Attributes.CM_P16:
|
|
91
|
-
case Attributes.CM_P256:
|
|
92
|
-
$bg = this._themeService.colors.ansi[this.result.fg & Attributes.PCOLOR_MASK].rgba;
|
|
93
|
-
break;
|
|
94
|
-
case Attributes.CM_RGB:
|
|
95
|
-
$bg = ((this.result.fg & Attributes.RGB_MASK) << 8) | 0xFF;
|
|
96
|
-
break;
|
|
97
|
-
case Attributes.CM_DEFAULT:
|
|
98
|
-
default:
|
|
99
|
-
$bg = this._themeService.colors.foreground.rgba;
|
|
100
|
-
}
|
|
101
|
-
} else {
|
|
102
|
-
switch (this.result.bg & Attributes.CM_MASK) {
|
|
103
|
-
case Attributes.CM_P16:
|
|
104
|
-
case Attributes.CM_P256:
|
|
105
|
-
$bg = this._themeService.colors.ansi[this.result.bg & Attributes.PCOLOR_MASK].rgba;
|
|
106
|
-
break;
|
|
107
|
-
case Attributes.CM_RGB:
|
|
108
|
-
$bg = ((this.result.bg & Attributes.RGB_MASK) << 8) | 0xFF;
|
|
109
|
-
break;
|
|
110
|
-
// No need to consider default bg color here as it's not possible
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// Blend with selection bg color
|
|
114
|
-
$bg = rgba.blend(
|
|
115
|
-
$bg,
|
|
116
|
-
((this._coreBrowserService.isFocused ? $colors.selectionBackgroundOpaque : $colors.selectionInactiveBackgroundOpaque).rgba & 0xFFFFFF00) | 0x80
|
|
117
|
-
) >> 8 & Attributes.RGB_MASK;
|
|
118
|
-
} else {
|
|
119
|
-
$bg = (this._coreBrowserService.isFocused ? $colors.selectionBackgroundOpaque : $colors.selectionInactiveBackgroundOpaque).rgba >> 8 & Attributes.RGB_MASK;
|
|
120
|
-
}
|
|
121
|
-
$hasBg = true;
|
|
122
|
-
|
|
123
|
-
// Apply explicit selection foreground if present
|
|
124
|
-
if ($colors.selectionForeground) {
|
|
125
|
-
$fg = $colors.selectionForeground.rgba >> 8 & Attributes.RGB_MASK;
|
|
126
|
-
$hasFg = true;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Overwrite fg as bg if it's a special decorative glyph (eg. powerline)
|
|
130
|
-
if (treatGlyphAsBackgroundColor(cell.getCode())) {
|
|
131
|
-
// Inverse default background should be treated as transparent
|
|
132
|
-
if (
|
|
133
|
-
(this.result.fg & FgFlags.INVERSE) &&
|
|
134
|
-
(this.result.bg & Attributes.CM_MASK) === Attributes.CM_DEFAULT
|
|
135
|
-
) {
|
|
136
|
-
$fg = (this._coreBrowserService.isFocused ? $colors.selectionBackgroundOpaque : $colors.selectionInactiveBackgroundOpaque).rgba >> 8 & Attributes.RGB_MASK;
|
|
137
|
-
} else {
|
|
138
|
-
|
|
139
|
-
if (this.result.fg & FgFlags.INVERSE) {
|
|
140
|
-
switch (this.result.bg & Attributes.CM_MASK) {
|
|
141
|
-
case Attributes.CM_P16:
|
|
142
|
-
case Attributes.CM_P256:
|
|
143
|
-
$fg = this._themeService.colors.ansi[this.result.bg & Attributes.PCOLOR_MASK].rgba;
|
|
144
|
-
break;
|
|
145
|
-
case Attributes.CM_RGB:
|
|
146
|
-
$fg = ((this.result.bg & Attributes.RGB_MASK) << 8) | 0xFF;
|
|
147
|
-
break;
|
|
148
|
-
// No need to consider default bg color here as it's not possible
|
|
149
|
-
}
|
|
150
|
-
} else {
|
|
151
|
-
switch (this.result.fg & Attributes.CM_MASK) {
|
|
152
|
-
case Attributes.CM_P16:
|
|
153
|
-
case Attributes.CM_P256:
|
|
154
|
-
$fg = this._themeService.colors.ansi[this.result.fg & Attributes.PCOLOR_MASK].rgba;
|
|
155
|
-
break;
|
|
156
|
-
case Attributes.CM_RGB:
|
|
157
|
-
$fg = ((this.result.fg & Attributes.RGB_MASK) << 8) | 0xFF;
|
|
158
|
-
break;
|
|
159
|
-
case Attributes.CM_DEFAULT:
|
|
160
|
-
default:
|
|
161
|
-
$fg = this._themeService.colors.foreground.rgba;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
$fg = rgba.blend(
|
|
166
|
-
$fg,
|
|
167
|
-
((this._coreBrowserService.isFocused ? $colors.selectionBackgroundOpaque : $colors.selectionInactiveBackgroundOpaque).rgba & 0xFFFFFF00) | 0x80
|
|
168
|
-
) >> 8 & Attributes.RGB_MASK;
|
|
169
|
-
}
|
|
170
|
-
$hasFg = true;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Apply decorations on the top layer
|
|
175
|
-
this._decorationService.forEachDecorationAtCell(x, y, 'top', d => {
|
|
176
|
-
if (d.backgroundColorRGB) {
|
|
177
|
-
$bg = d.backgroundColorRGB.rgba >> 8 & Attributes.RGB_MASK;
|
|
178
|
-
$hasBg = true;
|
|
179
|
-
}
|
|
180
|
-
if (d.foregroundColorRGB) {
|
|
181
|
-
$fg = d.foregroundColorRGB.rgba >> 8 & Attributes.RGB_MASK;
|
|
182
|
-
$hasFg = true;
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// Convert any overrides from rgba to the fg/bg packed format. This resolves the inverse flag
|
|
187
|
-
// ahead of time in order to use the correct cache key
|
|
188
|
-
if ($hasBg) {
|
|
189
|
-
if ($isSelected) {
|
|
190
|
-
// Non-RGB attributes from model + force non-dim + override + force RGB color mode
|
|
191
|
-
$bg = (cell.bg & ~Attributes.RGB_MASK & ~BgFlags.DIM) | $bg | Attributes.CM_RGB;
|
|
192
|
-
} else {
|
|
193
|
-
// Non-RGB attributes from model + override + force RGB color mode
|
|
194
|
-
$bg = (cell.bg & ~Attributes.RGB_MASK) | $bg | Attributes.CM_RGB;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if ($hasFg) {
|
|
198
|
-
// Non-RGB attributes from model + force disable inverse + override + force RGB color mode
|
|
199
|
-
$fg = (cell.fg & ~Attributes.RGB_MASK & ~FgFlags.INVERSE) | $fg | Attributes.CM_RGB;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Handle case where inverse was specified by only one of bg override or fg override was set,
|
|
203
|
-
// resolving the other inverse color and setting the inverse flag if needed.
|
|
204
|
-
if (this.result.fg & FgFlags.INVERSE) {
|
|
205
|
-
if ($hasBg && !$hasFg) {
|
|
206
|
-
// Resolve bg color type (default color has a different meaning in fg vs bg)
|
|
207
|
-
if ((this.result.bg & Attributes.CM_MASK) === Attributes.CM_DEFAULT) {
|
|
208
|
-
$fg = (this.result.fg & ~(Attributes.RGB_MASK | FgFlags.INVERSE | Attributes.CM_MASK)) | (($colors.background.rgba >> 8 & Attributes.RGB_MASK) & Attributes.RGB_MASK) | Attributes.CM_RGB;
|
|
209
|
-
} else {
|
|
210
|
-
$fg = (this.result.fg & ~(Attributes.RGB_MASK | FgFlags.INVERSE | Attributes.CM_MASK)) | this.result.bg & (Attributes.RGB_MASK | Attributes.CM_MASK);
|
|
211
|
-
}
|
|
212
|
-
$hasFg = true;
|
|
213
|
-
}
|
|
214
|
-
if (!$hasBg && $hasFg) {
|
|
215
|
-
// Resolve bg color type (default color has a different meaning in fg vs bg)
|
|
216
|
-
if ((this.result.fg & Attributes.CM_MASK) === Attributes.CM_DEFAULT) {
|
|
217
|
-
$bg = (this.result.bg & ~(Attributes.RGB_MASK | Attributes.CM_MASK)) | (($colors.foreground.rgba >> 8 & Attributes.RGB_MASK) & Attributes.RGB_MASK) | Attributes.CM_RGB;
|
|
218
|
-
} else {
|
|
219
|
-
$bg = (this.result.bg & ~(Attributes.RGB_MASK | Attributes.CM_MASK)) | this.result.fg & (Attributes.RGB_MASK | Attributes.CM_MASK);
|
|
220
|
-
}
|
|
221
|
-
$hasBg = true;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Release object
|
|
226
|
-
$colors = undefined;
|
|
227
|
-
|
|
228
|
-
// Use the override if it exists
|
|
229
|
-
this.result.bg = $hasBg ? $bg : this.result.bg;
|
|
230
|
-
this.result.fg = $hasFg ? $fg : this.result.fg;
|
|
231
|
-
|
|
232
|
-
// Reset overrides variantOffset
|
|
233
|
-
this.result.ext &= ~ExtFlags.VARIANT_OFFSET;
|
|
234
|
-
this.result.ext |= ($variantOffset << 29) & ExtFlags.VARIANT_OFFSET;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
|
3
|
-
* @license MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { TextureAtlas } from 'browser/renderer/shared/TextureAtlas';
|
|
7
|
-
import { ITerminalOptions, Terminal } from '@xterm/xterm';
|
|
8
|
-
import { ITerminal, ReadonlyColorSet } from 'browser/Types';
|
|
9
|
-
import { ICharAtlasConfig, ITextureAtlas } from 'browser/renderer/shared/Types';
|
|
10
|
-
import { generateConfig, configEquals } from 'browser/renderer/shared/CharAtlasUtils';
|
|
11
|
-
|
|
12
|
-
interface ITextureAtlasCacheEntry {
|
|
13
|
-
atlas: ITextureAtlas;
|
|
14
|
-
config: ICharAtlasConfig;
|
|
15
|
-
// N.B. This implementation potentially holds onto copies of the terminal forever, so
|
|
16
|
-
// this may cause memory leaks.
|
|
17
|
-
ownedBy: Terminal[];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const charAtlasCache: ITextureAtlasCacheEntry[] = [];
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Acquires a char atlas, either generating a new one or returning an existing
|
|
24
|
-
* one that is in use by another terminal.
|
|
25
|
-
*/
|
|
26
|
-
export function acquireTextureAtlas(
|
|
27
|
-
terminal: Terminal,
|
|
28
|
-
options: Required<ITerminalOptions>,
|
|
29
|
-
colors: ReadonlyColorSet,
|
|
30
|
-
deviceCellWidth: number,
|
|
31
|
-
deviceCellHeight: number,
|
|
32
|
-
deviceCharWidth: number,
|
|
33
|
-
deviceCharHeight: number,
|
|
34
|
-
devicePixelRatio: number,
|
|
35
|
-
deviceMaxTextureSize: number
|
|
36
|
-
): ITextureAtlas {
|
|
37
|
-
const newConfig = generateConfig(deviceCellWidth, deviceCellHeight, deviceCharWidth, deviceCharHeight, options, colors, devicePixelRatio, deviceMaxTextureSize);
|
|
38
|
-
|
|
39
|
-
// Check to see if the terminal already owns this config
|
|
40
|
-
for (let i = 0; i < charAtlasCache.length; i++) {
|
|
41
|
-
const entry = charAtlasCache[i];
|
|
42
|
-
const ownedByIndex = entry.ownedBy.indexOf(terminal);
|
|
43
|
-
if (ownedByIndex >= 0) {
|
|
44
|
-
if (configEquals(entry.config, newConfig)) {
|
|
45
|
-
return entry.atlas;
|
|
46
|
-
}
|
|
47
|
-
// The configs differ, release the terminal from the entry
|
|
48
|
-
if (entry.ownedBy.length === 1) {
|
|
49
|
-
entry.atlas.dispose();
|
|
50
|
-
charAtlasCache.splice(i, 1);
|
|
51
|
-
} else {
|
|
52
|
-
entry.ownedBy.splice(ownedByIndex, 1);
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Try match a char atlas from the cache
|
|
59
|
-
for (let i = 0; i < charAtlasCache.length; i++) {
|
|
60
|
-
const entry = charAtlasCache[i];
|
|
61
|
-
if (configEquals(entry.config, newConfig)) {
|
|
62
|
-
// Add the terminal to the cache entry and return
|
|
63
|
-
entry.ownedBy.push(terminal);
|
|
64
|
-
return entry.atlas;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const core: ITerminal = (terminal as any)._core;
|
|
69
|
-
const newEntry: ITextureAtlasCacheEntry = {
|
|
70
|
-
atlas: new TextureAtlas(document, newConfig, core.unicodeService),
|
|
71
|
-
config: newConfig,
|
|
72
|
-
ownedBy: [terminal]
|
|
73
|
-
};
|
|
74
|
-
charAtlasCache.push(newEntry);
|
|
75
|
-
return newEntry.atlas;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Removes a terminal reference from the cache, allowing its memory to be freed.
|
|
80
|
-
* @param terminal The terminal to remove.
|
|
81
|
-
*/
|
|
82
|
-
export function removeTerminalFromCache(terminal: Terminal): void {
|
|
83
|
-
for (let i = 0; i < charAtlasCache.length; i++) {
|
|
84
|
-
const index = charAtlasCache[i].ownedBy.indexOf(terminal);
|
|
85
|
-
if (index !== -1) {
|
|
86
|
-
if (charAtlasCache[i].ownedBy.length === 1) {
|
|
87
|
-
// Remove the cache entry if it's the only terminal
|
|
88
|
-
charAtlasCache[i].atlas.dispose();
|
|
89
|
-
charAtlasCache.splice(i, 1);
|
|
90
|
-
} else {
|
|
91
|
-
// Remove the reference from the cache entry
|
|
92
|
-
charAtlasCache[i].ownedBy.splice(index, 1);
|
|
93
|
-
}
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
|
3
|
-
* @license MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ICharAtlasConfig } from './Types';
|
|
7
|
-
import { Attributes } from 'common/buffer/Constants';
|
|
8
|
-
import { ITerminalOptions } from '@xterm/xterm';
|
|
9
|
-
import { IColorSet, ReadonlyColorSet } from 'browser/Types';
|
|
10
|
-
import { NULL_COLOR } from 'common/Color';
|
|
11
|
-
|
|
12
|
-
export function generateConfig(deviceCellWidth: number, deviceCellHeight: number, deviceCharWidth: number, deviceCharHeight: number, options: Required<ITerminalOptions>, colors: ReadonlyColorSet, devicePixelRatio: number, deviceMaxTextureSize: number): ICharAtlasConfig {
|
|
13
|
-
// null out some fields that don't matter
|
|
14
|
-
const clonedColors: IColorSet = {
|
|
15
|
-
foreground: colors.foreground,
|
|
16
|
-
background: colors.background,
|
|
17
|
-
cursor: NULL_COLOR,
|
|
18
|
-
cursorAccent: NULL_COLOR,
|
|
19
|
-
selectionForeground: NULL_COLOR,
|
|
20
|
-
selectionBackgroundTransparent: NULL_COLOR,
|
|
21
|
-
selectionBackgroundOpaque: NULL_COLOR,
|
|
22
|
-
selectionInactiveBackgroundTransparent: NULL_COLOR,
|
|
23
|
-
selectionInactiveBackgroundOpaque: NULL_COLOR,
|
|
24
|
-
overviewRulerBorder: NULL_COLOR,
|
|
25
|
-
scrollbarSliderBackground: NULL_COLOR,
|
|
26
|
-
scrollbarSliderHoverBackground: NULL_COLOR,
|
|
27
|
-
scrollbarSliderActiveBackground: NULL_COLOR,
|
|
28
|
-
// For the static char atlas, we only use the first 16 colors, but we need all 256 for the
|
|
29
|
-
// dynamic character atlas.
|
|
30
|
-
ansi: colors.ansi.slice(),
|
|
31
|
-
contrastCache: colors.contrastCache,
|
|
32
|
-
halfContrastCache: colors.halfContrastCache
|
|
33
|
-
};
|
|
34
|
-
return {
|
|
35
|
-
customGlyphs: options.customGlyphs,
|
|
36
|
-
devicePixelRatio,
|
|
37
|
-
deviceMaxTextureSize,
|
|
38
|
-
letterSpacing: options.letterSpacing,
|
|
39
|
-
lineHeight: options.lineHeight,
|
|
40
|
-
deviceCellWidth: deviceCellWidth,
|
|
41
|
-
deviceCellHeight: deviceCellHeight,
|
|
42
|
-
deviceCharWidth: deviceCharWidth,
|
|
43
|
-
deviceCharHeight: deviceCharHeight,
|
|
44
|
-
fontFamily: options.fontFamily,
|
|
45
|
-
fontSize: options.fontSize,
|
|
46
|
-
fontWeight: options.fontWeight,
|
|
47
|
-
fontWeightBold: options.fontWeightBold,
|
|
48
|
-
allowTransparency: options.allowTransparency,
|
|
49
|
-
drawBoldTextInBrightColors: options.drawBoldTextInBrightColors,
|
|
50
|
-
minimumContrastRatio: options.minimumContrastRatio,
|
|
51
|
-
colors: clonedColors
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean {
|
|
56
|
-
for (let i = 0; i < a.colors.ansi.length; i++) {
|
|
57
|
-
if (a.colors.ansi[i].rgba !== b.colors.ansi[i].rgba) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return a.devicePixelRatio === b.devicePixelRatio &&
|
|
62
|
-
a.customGlyphs === b.customGlyphs &&
|
|
63
|
-
a.lineHeight === b.lineHeight &&
|
|
64
|
-
a.letterSpacing === b.letterSpacing &&
|
|
65
|
-
a.fontFamily === b.fontFamily &&
|
|
66
|
-
a.fontSize === b.fontSize &&
|
|
67
|
-
a.fontWeight === b.fontWeight &&
|
|
68
|
-
a.fontWeightBold === b.fontWeightBold &&
|
|
69
|
-
a.allowTransparency === b.allowTransparency &&
|
|
70
|
-
a.deviceCharWidth === b.deviceCharWidth &&
|
|
71
|
-
a.deviceCharHeight === b.deviceCharHeight &&
|
|
72
|
-
a.drawBoldTextInBrightColors === b.drawBoldTextInBrightColors &&
|
|
73
|
-
a.minimumContrastRatio === b.minimumContrastRatio &&
|
|
74
|
-
a.colors.foreground.rgba === b.colors.foreground.rgba &&
|
|
75
|
-
a.colors.background.rgba === b.colors.background.rgba;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function is256Color(colorCode: number): boolean {
|
|
79
|
-
return (colorCode & Attributes.CM_MASK) === Attributes.CM_P16 || (colorCode & Attributes.CM_MASK) === Attributes.CM_P256;
|
|
80
|
-
}
|