Skip to content

Commit 6ba731d

Browse files
authored
Merge pull request #5867 from Tyriar/inst_const_enuym
Add disposable/const enum agent instructions, convert a lot of top level consts to const enums
2 parents 1023e40 + 2d3909b commit 6ba731d

20 files changed

Lines changed: 309 additions & 282 deletions

AGENTS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export class MyAddon implements ITerminalAddon {
5757
- Proposed APIs require `allowProposedApi: true` option
5858
- Constructor-only options (cols, rows) cannot be changed after instantiation
5959

60+
**Disposable Management**:
61+
- When a disposable object can be replaced over time, prefer a registered `MutableDisposable` over manual dispose/reassign logic.
62+
- Register it on the owning class (for example, `this._register(new MutableDisposable())`) and assign through `.value`; this automatically disposes the previous value and avoids accidentally leaking resources.
63+
64+
**TypeScript Constants**:
65+
- Prefer `const enum` over top-level `const` declarations for primitive constants when appropriate, since values are inlined and avoid runtime property lookups.
66+
6067
**Testing Utilities**: Use `TestUtils.ts` helpers:
6168
- `openTerminal(ctx, options)` for setup
6269
- `pollFor(page, fn, expectedValue)` for async assertions

addons/addon-fit/src/FitAddon.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ interface ITerminalDimensions {
1919
cols: number;
2020
}
2121

22-
const MINIMUM_COLS = 2;
23-
const MINIMUM_ROWS = 1;
22+
const enum Constants {
23+
MINIMUM_COLS = 2,
24+
MINIMUM_ROWS = 1
25+
}
2426

2527
function getWindow(e: Node): Window {
2628
if (e?.ownerDocument?.defaultView) {
@@ -86,8 +88,8 @@ export class FitAddon implements ITerminalAddon, IFitApi {
8688
const availableHeight = parentElementHeight - elementPaddingVer;
8789
const availableWidth = parentElementWidth - elementPaddingHor - scrollbarWidth;
8890
const geometry = {
89-
cols: Math.max(MINIMUM_COLS, Math.floor(availableWidth / dims.css.cell.width)),
90-
rows: Math.max(MINIMUM_ROWS, Math.floor(availableHeight / dims.css.cell.height))
91+
cols: Math.max(Constants.MINIMUM_COLS, Math.floor(availableWidth / dims.css.cell.width)),
92+
rows: Math.max(Constants.MINIMUM_ROWS, Math.floor(availableHeight / dims.css.cell.height))
9193
};
9294
return geometry;
9395
}

addons/addon-image/src/ImageRenderer.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import { IDisposable } from '@xterm/xterm';
88
import { ICellSize, ImageLayer, ITerminalExt, IImageSpec, IRenderDimensions, IRenderService } from './Types';
99
import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
1010

11-
const PLACEHOLDER_LENGTH = 4096;
12-
const PLACEHOLDER_HEIGHT = 24;
11+
const enum Constants {
12+
PLACEHOLDER_LENGTH = 4096,
13+
PLACEHOLDER_HEIGHT = 24
14+
}
1315

1416
/**
1517
* ImageRenderer - terminal frontend extension:
@@ -110,7 +112,7 @@ export class ImageRenderer extends Disposable implements IDisposable {
110112
public showPlaceholder(value: boolean): void {
111113
if (value) {
112114
if (!this._placeholder && this.cellSize.height !== -1) {
113-
this._createPlaceHolder(Math.max(this.cellSize.height + 1, PLACEHOLDER_HEIGHT));
115+
this._createPlaceHolder(Math.max(this.cellSize.height + 1, Constants.PLACEHOLDER_HEIGHT));
114116
}
115117
} else {
116118
this._placeholderBitmap?.close();
@@ -249,7 +251,7 @@ export class ImageRenderer extends Disposable implements IDisposable {
249251
}
250252

251253
if (!this._placeholder) {
252-
this._createPlaceHolder(Math.max(height + 1, PLACEHOLDER_HEIGHT));
254+
this._createPlaceHolder(Math.max(height + 1, Constants.PLACEHOLDER_HEIGHT));
253255
} else if (height >= this._placeholder!.height) {
254256
this._createPlaceHolder(height + 1);
255257
}
@@ -379,7 +381,7 @@ export class ImageRenderer extends Disposable implements IDisposable {
379381
return this._layers.has(layer);
380382
}
381383

382-
private _createPlaceHolder(height: number = PLACEHOLDER_HEIGHT): void {
384+
private _createPlaceHolder(height: number = Constants.PLACEHOLDER_HEIGHT): void {
383385
this._placeholderBitmap?.close();
384386
this._placeholderBitmap = undefined;
385387

@@ -403,7 +405,7 @@ export class ImageRenderer extends Disposable implements IDisposable {
403405
ctx.putImageData(imgData, 0, 0);
404406

405407
// create placeholder line, width aligned to blueprint width
406-
const width = (screen.width + bWidth - 1) & ~(bWidth - 1) || PLACEHOLDER_LENGTH;
408+
const width = (screen.width + bWidth - 1) & ~(bWidth - 1) || Constants.PLACEHOLDER_LENGTH;
407409
this._placeholder = ImageRenderer.createCanvas(this.document, width, height);
408410
const ctx2 = this._placeholder.getContext('2d', { alpha: false });
409411
if (!ctx2) {

addons/addon-image/src/kitty/KittyGraphicsHandler.ts

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,23 @@ import {
1616
IKittyCommand,
1717
IPendingTransmission,
1818
IKittyImageData,
19-
BYTES_PER_PIXEL_RGB,
20-
BYTES_PER_PIXEL_RGBA,
21-
ALPHA_OPAQUE,
19+
KittyPixelConstants,
2220
parseKittyCommand
2321
} from './KittyGraphicsTypes';
2422

25-
// Memory limit for base64 decoder (4MB, same as IIPHandler)
26-
const DECODER_KEEP_DATA = 4194304;
27-
const DECODER_INITIAL_DATA = 4194304; // 4MB
28-
29-
// Local mirror of const enum (esbuild can't inline const enums from external packages)
30-
const DECODER_OK: DecodeStatus.OK = 0;
31-
32-
// Maximum control data size
33-
const MAX_CONTROL_DATA_SIZE = 512;
23+
const enum Constants {
24+
// Memory limit for base64 decoder (4MB, same as IIPHandler)
25+
DECODER_KEEP_DATA = 4194304,
26+
DECODER_INITIAL_DATA = 4194304, // 4MB
27+
// Local mirror of const enum (esbuild can't inline const enums from external packages)
28+
DECODER_OK = 0,
29+
// Maximum control data size
30+
MAX_CONTROL_DATA_SIZE = 512,
31+
// Semicolon codepoint
32+
SEMICOLON = 0x3B
33+
}
3434

35-
// Semicolon codepoint
36-
const SEMICOLON = 0x3B;
35+
const DECODER_OK = Constants.DECODER_OK as unknown as DecodeStatus.OK;
3736

3837
// Kitty graphics protocol handler with streaming base64 decoding.
3938
export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDisposable {
@@ -50,7 +49,7 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
5049
private _inControlData = true;
5150

5251
// Buffer for control data.
53-
private _controlData = new Uint32Array(MAX_CONTROL_DATA_SIZE);
52+
private _controlData = new Uint32Array(Constants.MAX_CONTROL_DATA_SIZE);
5453
private _controlLength = 0;
5554

5655
// Pre-calculated encoded size limit
@@ -77,7 +76,7 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
7776
// Convert decoded size limit -> max encoded bytes.
7877
this._maxEncodedBytes = Math.ceil(this._opts.kittySizeLimit * 4 / 3);
7978
// ensure we preallocate more than configured limit while using 4mb initial size.
80-
this._initialEncodedBytes = Math.min(DECODER_INITIAL_DATA, this._maxEncodedBytes);
79+
this._initialEncodedBytes = Math.min(Constants.DECODER_INITIAL_DATA, this._maxEncodedBytes);
8180
}
8281

8382
public reset(): void {
@@ -129,7 +128,7 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
129128
// Scan for semicolon
130129
let controlEnd = end;
131130
for (let i = start; i < end; i++) {
132-
if (data[i] === SEMICOLON) {
131+
if (data[i] === Constants.SEMICOLON) {
133132
this._inControlData = false;
134133
controlEnd = i;
135134
break;
@@ -138,7 +137,7 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
138137

139138
// Copy control data
140139
const copyLength = controlEnd - start;
141-
if (this._controlLength + copyLength > MAX_CONTROL_DATA_SIZE) {
140+
if (this._controlLength + copyLength > Constants.MAX_CONTROL_DATA_SIZE) {
142141
this._aborted = true;
143142
return;
144143
}
@@ -201,7 +200,7 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
201200
this._activeDecoder = pending.decoder;
202201
}
203202
if (!this._activeDecoder) {
204-
this._activeDecoder = new Base64Decoder(DECODER_KEEP_DATA, this._maxEncodedBytes, this._initialEncodedBytes);
203+
this._activeDecoder = new Base64Decoder(Constants.DECODER_KEEP_DATA, this._maxEncodedBytes, this._initialEncodedBytes);
205204
this._activeDecoder.init();
206205
}
207206

@@ -484,7 +483,7 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
484483
return true;
485484
}
486485

487-
const bytesPerPixel = format === KittyFormat.RGBA ? BYTES_PER_PIXEL_RGBA : BYTES_PER_PIXEL_RGB;
486+
const bytesPerPixel = format === KittyFormat.RGBA ? KittyPixelConstants.BYTES_PER_PIXEL_RGBA : KittyPixelConstants.BYTES_PER_PIXEL_RGB;
488487
const expectedBytes = width * height * bytesPerPixel;
489488

490489
if (bytes.length < expectedBytes) {
@@ -723,7 +722,7 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
723722
throw new Error('Width and height required for raw pixel data');
724723
}
725724

726-
const bytesPerPixel = image.format === KittyFormat.RGBA ? BYTES_PER_PIXEL_RGBA : BYTES_PER_PIXEL_RGB;
725+
const bytesPerPixel = image.format === KittyFormat.RGBA ? KittyPixelConstants.BYTES_PER_PIXEL_RGBA : KittyPixelConstants.BYTES_PER_PIXEL_RGB;
727726
const expectedBytes = width * height * bytesPerPixel;
728727

729728
if (bytes.length < expectedBytes) {
@@ -734,13 +733,13 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
734733

735734
if (image.format === KittyFormat.RGBA) {
736735
// RGBA: use bytes directly — no copy needed
737-
return createImageBitmap(new ImageData(new Uint8ClampedArray(bytes.buffer as ArrayBuffer, bytes.byteOffset, pixelCount * BYTES_PER_PIXEL_RGBA), width, height));
736+
return createImageBitmap(new ImageData(new Uint8ClampedArray(bytes.buffer as ArrayBuffer, bytes.byteOffset, pixelCount * KittyPixelConstants.BYTES_PER_PIXEL_RGBA), width, height));
738737
}
739738

740739
// RGB→RGBA: interleave alpha using uint32 block processing (4 pixels per iteration).
741740
// 3 uint32 reads + 4 uint32 writes per 4 pixels vs 28 byte reads/writes — ~6x faster.
742741
// Assumes little-endian (all modern browsers/Node.js).
743-
const data = new Uint8ClampedArray(pixelCount * BYTES_PER_PIXEL_RGBA);
742+
const data = new Uint8ClampedArray(pixelCount * KittyPixelConstants.BYTES_PER_PIXEL_RGBA);
744743
const src32 = new Uint32Array(bytes.buffer, bytes.byteOffset, Math.floor(bytes.byteLength / 4));
745744
const dst32 = new Uint32Array(data.buffer);
746745
const alignedPixels = pixelCount & ~3; // round down to multiple of 4
@@ -759,15 +758,15 @@ export class KittyGraphicsHandler implements IApcHandler, IResetHandler, IDispos
759758
}
760759

761760
// Handle remaining 1–3 pixels
762-
let srcByte = alignedPixels * BYTES_PER_PIXEL_RGB;
763-
let dstByte = alignedPixels * BYTES_PER_PIXEL_RGBA;
761+
let srcByte = alignedPixels * KittyPixelConstants.BYTES_PER_PIXEL_RGB;
762+
let dstByte = alignedPixels * KittyPixelConstants.BYTES_PER_PIXEL_RGBA;
764763
for (let i = alignedPixels; i < pixelCount; i++) {
765764
data[dstByte] = bytes[srcByte];
766765
data[dstByte + 1] = bytes[srcByte + 1];
767766
data[dstByte + 2] = bytes[srcByte + 2];
768-
data[dstByte + 3] = ALPHA_OPAQUE;
769-
srcByte += BYTES_PER_PIXEL_RGB;
770-
dstByte += BYTES_PER_PIXEL_RGBA;
767+
data[dstByte + 3] = KittyPixelConstants.ALPHA_OPAQUE;
768+
srcByte += KittyPixelConstants.BYTES_PER_PIXEL_RGB;
769+
dstByte += KittyPixelConstants.BYTES_PER_PIXEL_RGBA;
771770
}
772771

773772
return createImageBitmap(new ImageData(data, width, height));

addons/addon-image/src/kitty/KittyGraphicsTypes.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ export const enum KittyKey {
8282
}
8383

8484
// Pixel format constants
85-
export const BYTES_PER_PIXEL_RGB = 3;
86-
export const BYTES_PER_PIXEL_RGBA = 4;
87-
export const ALPHA_OPAQUE = 255;
85+
export const enum KittyPixelConstants {
86+
BYTES_PER_PIXEL_RGB = 3,
87+
BYTES_PER_PIXEL_RGBA = 4,
88+
ALPHA_OPAQUE = 255
89+
}
8890

8991
// Parsed Kitty graphics command.
9092
export interface IKittyCommand {

addons/addon-webgl/src/GlyphRenderer.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ void main() {
7878
}`);
7979
}
8080

81-
const INDICES_PER_CELL = 11;
82-
const BYTES_PER_CELL = INDICES_PER_CELL * Float32Array.BYTES_PER_ELEMENT;
83-
const CELL_POSITION_INDICES = 2;
81+
const enum Constants {
82+
INDICES_PER_CELL = 11,
83+
BYTES_PER_CELL = INDICES_PER_CELL * 4/* Float32Array.BYTES_PER_ELEMENT */,
84+
CELL_POSITION_INDICES = 2
85+
}
8486

8587
// Work variables to avoid garbage collection
8688
let $i = 0;
@@ -160,22 +162,22 @@ export class GlyphRenderer extends Disposable {
160162
this._register(toDisposable(() => gl.deleteBuffer(this._attributesBuffer)));
161163
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
162164
gl.enableVertexAttribArray(VertexAttribLocations.OFFSET);
163-
gl.vertexAttribPointer(VertexAttribLocations.OFFSET, 2, gl.FLOAT, false, BYTES_PER_CELL, 0);
165+
gl.vertexAttribPointer(VertexAttribLocations.OFFSET, 2, gl.FLOAT, false, Constants.BYTES_PER_CELL, 0);
164166
gl.vertexAttribDivisor(VertexAttribLocations.OFFSET, 1);
165167
gl.enableVertexAttribArray(VertexAttribLocations.SIZE);
166-
gl.vertexAttribPointer(VertexAttribLocations.SIZE, 2, gl.FLOAT, false, BYTES_PER_CELL, 2 * Float32Array.BYTES_PER_ELEMENT);
168+
gl.vertexAttribPointer(VertexAttribLocations.SIZE, 2, gl.FLOAT, false, Constants.BYTES_PER_CELL, 2 * Float32Array.BYTES_PER_ELEMENT);
167169
gl.vertexAttribDivisor(VertexAttribLocations.SIZE, 1);
168170
gl.enableVertexAttribArray(VertexAttribLocations.TEXPAGE);
169-
gl.vertexAttribPointer(VertexAttribLocations.TEXPAGE, 1, gl.FLOAT, false, BYTES_PER_CELL, 4 * Float32Array.BYTES_PER_ELEMENT);
171+
gl.vertexAttribPointer(VertexAttribLocations.TEXPAGE, 1, gl.FLOAT, false, Constants.BYTES_PER_CELL, 4 * Float32Array.BYTES_PER_ELEMENT);
170172
gl.vertexAttribDivisor(VertexAttribLocations.TEXPAGE, 1);
171173
gl.enableVertexAttribArray(VertexAttribLocations.TEXCOORD);
172-
gl.vertexAttribPointer(VertexAttribLocations.TEXCOORD, 2, gl.FLOAT, false, BYTES_PER_CELL, 5 * Float32Array.BYTES_PER_ELEMENT);
174+
gl.vertexAttribPointer(VertexAttribLocations.TEXCOORD, 2, gl.FLOAT, false, Constants.BYTES_PER_CELL, 5 * Float32Array.BYTES_PER_ELEMENT);
173175
gl.vertexAttribDivisor(VertexAttribLocations.TEXCOORD, 1);
174176
gl.enableVertexAttribArray(VertexAttribLocations.TEXSIZE);
175-
gl.vertexAttribPointer(VertexAttribLocations.TEXSIZE, 2, gl.FLOAT, false, BYTES_PER_CELL, 7 * Float32Array.BYTES_PER_ELEMENT);
177+
gl.vertexAttribPointer(VertexAttribLocations.TEXSIZE, 2, gl.FLOAT, false, Constants.BYTES_PER_CELL, 7 * Float32Array.BYTES_PER_ELEMENT);
176178
gl.vertexAttribDivisor(VertexAttribLocations.TEXSIZE, 1);
177179
gl.enableVertexAttribArray(VertexAttribLocations.CELL_POSITION);
178-
gl.vertexAttribPointer(VertexAttribLocations.CELL_POSITION, 2, gl.FLOAT, false, BYTES_PER_CELL, 9 * Float32Array.BYTES_PER_ELEMENT);
180+
gl.vertexAttribPointer(VertexAttribLocations.CELL_POSITION, 2, gl.FLOAT, false, Constants.BYTES_PER_CELL, 9 * Float32Array.BYTES_PER_ELEMENT);
179181
gl.vertexAttribDivisor(VertexAttribLocations.CELL_POSITION, 1);
180182

181183
// Setup static uniforms
@@ -222,12 +224,12 @@ export class GlyphRenderer extends Disposable {
222224
}
223225

224226
private _updateCell(array: Float32Array, x: number, y: number, code: number | undefined, bg: number, fg: number, ext: number, chars: string, width: number, lastBg: number): void {
225-
$i = (y * this._terminal.cols + x) * INDICES_PER_CELL;
227+
$i = (y * this._terminal.cols + x) * Constants.INDICES_PER_CELL;
226228

227229
// Exit early if this is a null character, allow space character to continue as it may have
228230
// underline/strikethrough styles
229231
if (code === NULL_CELL_CODE || code === undefined/* This is used for the right side of wide chars */) {
230-
array.fill(0, $i, $i + INDICES_PER_CELL - 1 - CELL_POSITION_INDICES);
232+
array.fill(0, $i, $i + Constants.INDICES_PER_CELL - 1 - Constants.CELL_POSITION_INDICES);
231233
return;
232234
}
233235

@@ -288,7 +290,7 @@ export class GlyphRenderer extends Disposable {
288290

289291
public clear(): void {
290292
const terminal = this._terminal;
291-
const newCount = terminal.cols * terminal.rows * INDICES_PER_CELL;
293+
const newCount = terminal.cols * terminal.rows * Constants.INDICES_PER_CELL;
292294

293295
// Clear vertices
294296
if (this._vertices.count !== newCount) {
@@ -310,7 +312,7 @@ export class GlyphRenderer extends Disposable {
310312
for (let x = 0; x < terminal.cols; x++) {
311313
this._vertices.attributes[i + 9] = x / terminal.cols;
312314
this._vertices.attributes[i + 10] = y / terminal.rows;
313-
i += INDICES_PER_CELL;
315+
i += Constants.INDICES_PER_CELL;
314316
}
315317
}
316318
}
@@ -346,8 +348,8 @@ export class GlyphRenderer extends Disposable {
346348
// - So we don't send vertices for all the line-ending whitespace to the GPU
347349
let bufferLength = 0;
348350
for (let y = 0; y < renderModel.lineLengths.length; y++) {
349-
const si = y * this._terminal.cols * INDICES_PER_CELL;
350-
const sub = this._vertices.attributes.subarray(si, si + renderModel.lineLengths[y] * INDICES_PER_CELL);
351+
const si = y * this._terminal.cols * Constants.INDICES_PER_CELL;
352+
const sub = this._vertices.attributes.subarray(si, si + renderModel.lineLengths[y] * Constants.INDICES_PER_CELL);
351353
activeBuffer.set(sub, bufferLength);
352354
bufferLength += sub.length;
353355
}
@@ -364,7 +366,7 @@ export class GlyphRenderer extends Disposable {
364366
}
365367

366368
// Draw the viewport
367-
gl.drawElementsInstanced(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_BYTE, 0, bufferLength / INDICES_PER_CELL);
369+
gl.drawElementsInstanced(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_BYTE, 0, bufferLength / Constants.INDICES_PER_CELL);
368370
}
369371

370372
public setAtlas(atlas: ITextureAtlas): void {

addons/addon-webgl/src/RectangleRenderer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Attributes, FgFlags } from 'common/buffer/Constants';
1010
import { Disposable, toDisposable } from 'common/Lifecycle';
1111
import { IColor } from 'common/Types';
1212
import { Terminal } from '@xterm/xterm';
13-
import { RENDER_MODEL_BG_OFFSET, RENDER_MODEL_FG_OFFSET, RENDER_MODEL_INDICIES_PER_CELL } from './RenderModel';
13+
import { RenderModelConstants } from './RenderModel';
1414
import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject } from './Types';
1515
import { createProgram, expandFloat32Array, PROJECTION_MATRIX } from './WebglUtils';
1616
import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
@@ -217,9 +217,9 @@ export class RectangleRenderer extends Disposable {
217217
currentFg = 0;
218218
currentInverse = false;
219219
for (x = 0; x < terminal.cols; x++) {
220-
modelIndex = ((y * terminal.cols) + x) * RENDER_MODEL_INDICIES_PER_CELL;
221-
bg = model.cells[modelIndex + RENDER_MODEL_BG_OFFSET];
222-
fg = model.cells[modelIndex + RENDER_MODEL_FG_OFFSET];
220+
modelIndex = ((y * terminal.cols) + x) * RenderModelConstants.INDICIES_PER_CELL;
221+
bg = model.cells[modelIndex + RenderModelConstants.BG_OFFSET];
222+
fg = model.cells[modelIndex + RenderModelConstants.FG_OFFSET];
223223
inverse = !!(fg & FgFlags.INVERSE);
224224
if (bg !== currentBg || (fg !== currentFg && (currentInverse || inverse))) {
225225
// A rectangle needs to be drawn if going from non-default to another color

addons/addon-webgl/src/RenderModel.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import { ICursorRenderModel, IRenderModel } from './Types';
77
import { ISelectionRenderModel } from 'browser/renderer/shared/Types';
88
import { createSelectionRenderModel } from 'browser/renderer/shared/SelectionRenderModel';
99

10-
export const RENDER_MODEL_INDICIES_PER_CELL = 4;
11-
export const RENDER_MODEL_BG_OFFSET = 1;
12-
export const RENDER_MODEL_FG_OFFSET = 2;
13-
export const RENDER_MODEL_EXT_OFFSET = 3;
10+
export const enum RenderModelConstants {
11+
INDICIES_PER_CELL = 4,
12+
BG_OFFSET = 1,
13+
FG_OFFSET = 2,
14+
EXT_OFFSET = 3
15+
}
1416

1517
export const COMBINED_CHAR_BIT_MASK = 0x80000000;
1618

@@ -27,7 +29,7 @@ export class RenderModel implements IRenderModel {
2729
}
2830

2931
public resize(cols: number, rows: number): void {
30-
const indexCount = cols * rows * RENDER_MODEL_INDICIES_PER_CELL;
32+
const indexCount = cols * rows * RenderModelConstants.INDICIES_PER_CELL;
3133
if (indexCount !== this.cells.length) {
3234
this.cells = new Uint32Array(indexCount);
3335
this.lineLengths = new Uint32Array(rows);

0 commit comments

Comments
 (0)