Skip to content

Commit cb3bd46

Browse files
authored
Merge pull request #5106 from Tyriar/tyriar/lifecycle
Move to vs/base disposables
2 parents b192ba2 + 56ec862 commit cb3bd46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+366
-646
lines changed

addons/addon-image/src/ImageRenderer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import { toRGBA8888 } from 'sixel/lib/Colors';
77
import { IDisposable } from '@xterm/xterm';
88
import { ICellSize, ITerminalExt, IImageSpec, IRenderDimensions, IRenderService } from './Types';
9-
import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
10-
9+
import { Disposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
1110

1211
const PLACEHOLDER_LENGTH = 4096;
1312
const PLACEHOLDER_HEIGHT = 24;
@@ -23,7 +22,7 @@ export class ImageRenderer extends Disposable implements IDisposable {
2322
private _ctx: CanvasRenderingContext2D | null | undefined;
2423
private _placeholder: HTMLCanvasElement | undefined;
2524
private _placeholderBitmap: ImageBitmap | undefined;
26-
private _optionsRefresh = this.register(new MutableDisposable());
25+
private _optionsRefresh = this._register(new MutableDisposable());
2726
private _oldOpen: ((parent: HTMLElement) => void) | undefined;
2827
private _renderService: IRenderService | undefined;
2928
private _oldSetRenderer: ((renderer: any) => void) | undefined;
@@ -85,7 +84,7 @@ export class ImageRenderer extends Disposable implements IDisposable {
8584
this._renderService?.refreshRows(0, this._terminal.rows);
8685
}
8786
});
88-
this.register(toDisposable(() => {
87+
this._register(toDisposable(() => {
8988
this.removeLayerFromDom();
9089
if (this._terminal._core && this._oldOpen) {
9190
this._terminal._core.open = this._oldOpen;

addons/addon-image/src/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"paths": {
1616
"browser/*": [ "../../../src/browser/*" ],
1717
"common/*": [ "../../../src/common/*" ],
18+
"vs/*": [ "../../../src/vs/*" ],
1819
"@xterm/addon-image": [ "../typings/addon-image.d.ts" ]
1920
}
2021
},
@@ -24,6 +25,7 @@
2425
],
2526
"references": [
2627
{ "path": "../../../src/browser" },
27-
{ "path": "../../../src/common" }
28+
{ "path": "../../../src/common" },
29+
{ "path": "../../../src/vs" }
2830
]
2931
}

addons/addon-image/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const addon = {
2626
extensions: [ '.js' ],
2727
alias: {
2828
common: path.resolve('../../out/common'),
29-
browser: path.resolve('../../out/browser')
29+
browser: path.resolve('../../out/browser'),
30+
vs: path.resolve('../../out/vs')
3031
}
3132
},
3233
output: {

addons/addon-search/src/SearchAddon.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm';
77
import type { SearchAddon as ISearchApi } from '@xterm/addon-search';
8-
import { Disposable, toDisposable, disposeArray, MutableDisposable, getDisposeArrayDisposable } from 'common/Lifecycle';
98
import { Emitter } from 'vs/base/common/event';
9+
import { combinedDisposable, Disposable, dispose, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
1010

1111
export interface ISearchOptions {
1212
regex?: boolean;
@@ -67,7 +67,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
6767
private _cachedSearchTerm: string | undefined;
6868
private _highlightedLines: Set<number> = new Set();
6969
private _highlightDecorations: IHighlight[] = [];
70-
private _selectedDecoration: MutableDisposable<IHighlight> = this.register(new MutableDisposable());
70+
private _selectedDecoration: MutableDisposable<IHighlight> = this._register(new MutableDisposable());
7171
private _highlightLimit: number;
7272
private _lastSearchOptions: ISearchOptions | undefined;
7373
private _highlightTimeout: number | undefined;
@@ -80,7 +80,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
8080
private _linesCacheTimeoutId = 0;
8181
private _linesCacheDisposables = new MutableDisposable();
8282

83-
private readonly _onDidChangeResults = this.register(new Emitter<{ resultIndex: number, resultCount: number }>());
83+
private readonly _onDidChangeResults = this._register(new Emitter<{ resultIndex: number, resultCount: number }>());
8484
public readonly onDidChangeResults = this._onDidChangeResults.event;
8585

8686
constructor(options?: Partial<ISearchAddonOptions>) {
@@ -91,9 +91,9 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
9191

9292
public activate(terminal: Terminal): void {
9393
this._terminal = terminal;
94-
this.register(this._terminal.onWriteParsed(() => this._updateMatches()));
95-
this.register(this._terminal.onResize(() => this._updateMatches()));
96-
this.register(toDisposable(() => this.clearDecorations()));
94+
this._register(this._terminal.onWriteParsed(() => this._updateMatches()));
95+
this._register(this._terminal.onResize(() => this._updateMatches()));
96+
this._register(toDisposable(() => this.clearDecorations()));
9797
}
9898

9999
private _updateMatches(): void {
@@ -111,7 +111,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
111111

112112
public clearDecorations(retainCachedSearchTerm?: boolean): void {
113113
this._selectedDecoration.clear();
114-
disposeArray(this._highlightDecorations);
114+
dispose(this._highlightDecorations);
115115
this._highlightDecorations = [];
116116
this._highlightedLines.clear();
117117
if (!retainCachedSearchTerm) {
@@ -426,11 +426,11 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
426426
const terminal = this._terminal!;
427427
if (!this._linesCache) {
428428
this._linesCache = new Array(terminal.buffer.active.length);
429-
this._linesCacheDisposables.value = getDisposeArrayDisposable([
429+
this._linesCacheDisposables.value = combinedDisposable(
430430
terminal.onLineFeed(() => this._destroyLinesCache()),
431431
terminal.onCursorMove(() => this._destroyLinesCache()),
432432
terminal.onResize(() => this._destroyLinesCache())
433-
]);
433+
);
434434
}
435435

436436
window.clearTimeout(this._linesCacheTimeoutId);
@@ -678,7 +678,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
678678
const disposables: IDisposable[] = [];
679679
disposables.push(marker);
680680
disposables.push(decoration.onRender((e) => this._applyStyles(e, options.activeMatchBorder, true)));
681-
disposables.push(decoration.onDispose(() => disposeArray(disposables)));
681+
disposables.push(decoration.onDispose(() => dispose(disposables)));
682682
this._selectedDecoration.value = { decoration, match: result, dispose() { decoration.dispose(); } };
683683
}
684684
}
@@ -740,7 +740,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
740740
const disposables: IDisposable[] = [];
741741
disposables.push(marker);
742742
disposables.push(findResultDecoration.onRender((e) => this._applyStyles(e, options.matchBorder, false)));
743-
disposables.push(findResultDecoration.onDispose(() => disposeArray(disposables)));
743+
disposables.push(findResultDecoration.onDispose(() => dispose(disposables)));
744744
}
745745
return findResultDecoration;
746746
}

addons/addon-webgl/src/GlyphRenderer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { allowRescaling, throwIfFalsy } from 'browser/renderer/shared/RendererUt
77
import { TextureAtlas } from 'browser/renderer/shared/TextureAtlas';
88
import { IRasterizedGlyph, IRenderDimensions, ITextureAtlas } from 'browser/renderer/shared/Types';
99
import { NULL_CELL_CODE } from 'common/buffer/Constants';
10-
import { Disposable, toDisposable } from 'common/Lifecycle';
10+
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
1111
import { Terminal } from '@xterm/xterm';
1212
import { IRenderModel, IWebGL2RenderingContext, IWebGLVertexArrayObject } from './Types';
1313
import { createProgram, GLTexture, PROJECTION_MATRIX } from './WebglUtils';
@@ -127,7 +127,7 @@ export class GlyphRenderer extends Disposable {
127127
}
128128

129129
this._program = throwIfFalsy(createProgram(gl, vertexShaderSource, createFragmentShaderSource(TextureAtlas.maxAtlasPages)));
130-
this.register(toDisposable(() => gl.deleteProgram(this._program)));
130+
this._register(toDisposable(() => gl.deleteProgram(this._program)));
131131

132132
// Uniform locations
133133
this._projectionLocation = throwIfFalsy(gl.getUniformLocation(this._program, 'u_projection'));
@@ -141,7 +141,7 @@ export class GlyphRenderer extends Disposable {
141141
// Setup a_unitquad, this defines the 4 vertices of a rectangle
142142
const unitQuadVertices = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
143143
const unitQuadVerticesBuffer = gl.createBuffer();
144-
this.register(toDisposable(() => gl.deleteBuffer(unitQuadVerticesBuffer)));
144+
this._register(toDisposable(() => gl.deleteBuffer(unitQuadVerticesBuffer)));
145145
gl.bindBuffer(gl.ARRAY_BUFFER, unitQuadVerticesBuffer);
146146
gl.bufferData(gl.ARRAY_BUFFER, unitQuadVertices, gl.STATIC_DRAW);
147147
gl.enableVertexAttribArray(VertexAttribLocations.UNIT_QUAD);
@@ -152,13 +152,13 @@ export class GlyphRenderer extends Disposable {
152152
// triangle strip
153153
const unitQuadElementIndices = new Uint8Array([0, 1, 2, 3]);
154154
const elementIndicesBuffer = gl.createBuffer();
155-
this.register(toDisposable(() => gl.deleteBuffer(elementIndicesBuffer)));
155+
this._register(toDisposable(() => gl.deleteBuffer(elementIndicesBuffer)));
156156
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementIndicesBuffer);
157157
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, unitQuadElementIndices, gl.STATIC_DRAW);
158158

159159
// Setup attributes
160160
this._attributesBuffer = throwIfFalsy(gl.createBuffer());
161-
this.register(toDisposable(() => gl.deleteBuffer(this._attributesBuffer)));
161+
this._register(toDisposable(() => gl.deleteBuffer(this._attributesBuffer)));
162162
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
163163
gl.enableVertexAttribArray(VertexAttribLocations.OFFSET);
164164
gl.vertexAttribPointer(VertexAttribLocations.OFFSET, 2, gl.FLOAT, false, BYTES_PER_CELL, 0);
@@ -193,7 +193,7 @@ export class GlyphRenderer extends Disposable {
193193
this._atlasTextures = [];
194194
for (let i = 0; i < TextureAtlas.maxAtlasPages; i++) {
195195
const glTexture = new GLTexture(throwIfFalsy(gl.createTexture()));
196-
this.register(toDisposable(() => gl.deleteTexture(glTexture.texture)));
196+
this._register(toDisposable(() => gl.deleteTexture(glTexture.texture)));
197197
gl.activeTexture(gl.TEXTURE0 + i);
198198
gl.bindTexture(gl.TEXTURE_2D, glTexture.texture);
199199
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);

addons/addon-webgl/src/RectangleRenderer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { IRenderDimensions } from 'browser/renderer/shared/Types';
88
import { IThemeService } from 'browser/services/Services';
99
import { ReadonlyColorSet } from 'browser/Types';
1010
import { Attributes, FgFlags } from 'common/buffer/Constants';
11-
import { Disposable, toDisposable } from 'common/Lifecycle';
11+
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
1212
import { IColor } from 'common/Types';
1313
import { Terminal } from '@xterm/xterm';
1414
import { RENDER_MODEL_BG_OFFSET, RENDER_MODEL_FG_OFFSET, RENDER_MODEL_INDICIES_PER_CELL } from './RenderModel';
@@ -96,7 +96,7 @@ export class RectangleRenderer extends Disposable {
9696
const gl = this._gl;
9797

9898
this._program = throwIfFalsy(createProgram(gl, vertexShaderSource, fragmentShaderSource));
99-
this.register(toDisposable(() => gl.deleteProgram(this._program)));
99+
this._register(toDisposable(() => gl.deleteProgram(this._program)));
100100

101101
// Uniform locations
102102
this._projectionLocation = throwIfFalsy(gl.getUniformLocation(this._program, 'u_projection'));
@@ -108,7 +108,7 @@ export class RectangleRenderer extends Disposable {
108108
// Setup a_unitquad, this defines the 4 vertices of a rectangle
109109
const unitQuadVertices = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
110110
const unitQuadVerticesBuffer = gl.createBuffer();
111-
this.register(toDisposable(() => gl.deleteBuffer(unitQuadVerticesBuffer)));
111+
this._register(toDisposable(() => gl.deleteBuffer(unitQuadVerticesBuffer)));
112112
gl.bindBuffer(gl.ARRAY_BUFFER, unitQuadVerticesBuffer);
113113
gl.bufferData(gl.ARRAY_BUFFER, unitQuadVertices, gl.STATIC_DRAW);
114114
gl.enableVertexAttribArray(VertexAttribLocations.UNIT_QUAD);
@@ -119,13 +119,13 @@ export class RectangleRenderer extends Disposable {
119119
// triangle strip
120120
const unitQuadElementIndices = new Uint8Array([0, 1, 2, 3]);
121121
const elementIndicesBuffer = gl.createBuffer();
122-
this.register(toDisposable(() => gl.deleteBuffer(elementIndicesBuffer)));
122+
this._register(toDisposable(() => gl.deleteBuffer(elementIndicesBuffer)));
123123
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementIndicesBuffer);
124124
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, unitQuadElementIndices, gl.STATIC_DRAW);
125125

126126
// Setup attributes
127127
this._attributesBuffer = throwIfFalsy(gl.createBuffer());
128-
this.register(toDisposable(() => gl.deleteBuffer(this._attributesBuffer)));
128+
this._register(toDisposable(() => gl.deleteBuffer(this._attributesBuffer)));
129129
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
130130
gl.enableVertexAttribArray(VertexAttribLocations.POSITION);
131131
gl.vertexAttribPointer(VertexAttribLocations.POSITION, 2, gl.FLOAT, false, BYTES_PER_RECTANGLE, 0);
@@ -138,7 +138,7 @@ export class RectangleRenderer extends Disposable {
138138
gl.vertexAttribDivisor(VertexAttribLocations.COLOR, 1);
139139

140140
this._updateCachedColors(_themeService.colors);
141-
this.register(this._themeService.onChangeColors(e => {
141+
this._register(this._themeService.onChangeColors(e => {
142142
this._updateCachedColors(e);
143143
this._updateViewportRectangle();
144144
}));

addons/addon-webgl/src/WebglAddon.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { ITerminalAddon, Terminal } from '@xterm/xterm';
77
import type { WebglAddon as IWebglApi } from '@xterm/addon-webgl';
88
import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
99
import { ITerminal } from 'browser/Types';
10-
import { Disposable, toDisposable } from 'common/Lifecycle';
10+
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
1111
import { getSafariVersion, isSafari } from 'common/Platform';
1212
import { ICoreService, IDecorationService, ILogService, IOptionsService } from 'common/services/Services';
1313
import { IWebGL2RenderingContext } from './Types';
@@ -19,13 +19,13 @@ export class WebglAddon extends Disposable implements ITerminalAddon , IWebglApi
1919
private _terminal?: Terminal;
2020
private _renderer?: WebglRenderer;
2121

22-
private readonly _onChangeTextureAtlas = this.register(new Emitter<HTMLCanvasElement>());
22+
private readonly _onChangeTextureAtlas = this._register(new Emitter<HTMLCanvasElement>());
2323
public readonly onChangeTextureAtlas = this._onChangeTextureAtlas.event;
24-
private readonly _onAddTextureAtlasCanvas = this.register(new Emitter<HTMLCanvasElement>());
24+
private readonly _onAddTextureAtlasCanvas = this._register(new Emitter<HTMLCanvasElement>());
2525
public readonly onAddTextureAtlasCanvas = this._onAddTextureAtlasCanvas.event;
26-
private readonly _onRemoveTextureAtlasCanvas = this.register(new Emitter<HTMLCanvasElement>());
26+
private readonly _onRemoveTextureAtlasCanvas = this._register(new Emitter<HTMLCanvasElement>());
2727
public readonly onRemoveTextureAtlasCanvas = this._onRemoveTextureAtlasCanvas.event;
28-
private readonly _onContextLoss = this.register(new Emitter<void>());
28+
private readonly _onContextLoss = this._register(new Emitter<void>());
2929
public readonly onContextLoss = this._onContextLoss.event;
3030

3131
constructor(
@@ -49,7 +49,7 @@ export class WebglAddon extends Disposable implements ITerminalAddon , IWebglApi
4949
public activate(terminal: Terminal): void {
5050
const core = (terminal as any)._core as ITerminal;
5151
if (!terminal.element) {
52-
this.register(core.onWillOpen(() => this.activate(terminal)));
52+
this._register(core.onWillOpen(() => this.activate(terminal)));
5353
return;
5454
}
5555

@@ -70,7 +70,7 @@ export class WebglAddon extends Disposable implements ITerminalAddon , IWebglApi
7070
// bundled separately to the core module
7171
setTraceLogger(logService);
7272

73-
this._renderer = this.register(new WebglRenderer(
73+
this._renderer = this._register(new WebglRenderer(
7474
terminal,
7575
characterJoinerService,
7676
charSizeService,
@@ -81,13 +81,13 @@ export class WebglAddon extends Disposable implements ITerminalAddon , IWebglApi
8181
themeService,
8282
this._preserveDrawingBuffer
8383
));
84-
this.register(Event.forward(this._renderer.onContextLoss, this._onContextLoss));
85-
this.register(Event.forward(this._renderer.onChangeTextureAtlas, this._onChangeTextureAtlas));
86-
this.register(Event.forward(this._renderer.onAddTextureAtlasCanvas, this._onAddTextureAtlasCanvas));
87-
this.register(Event.forward(this._renderer.onRemoveTextureAtlasCanvas, this._onRemoveTextureAtlasCanvas));
84+
this._register(Event.forward(this._renderer.onContextLoss, this._onContextLoss));
85+
this._register(Event.forward(this._renderer.onChangeTextureAtlas, this._onChangeTextureAtlas));
86+
this._register(Event.forward(this._renderer.onAddTextureAtlasCanvas, this._onAddTextureAtlasCanvas));
87+
this._register(Event.forward(this._renderer.onRemoveTextureAtlasCanvas, this._onRemoveTextureAtlasCanvas));
8888
renderService.setRenderer(this._renderer);
8989

90-
this.register(toDisposable(() => {
90+
this._register(toDisposable(() => {
9191
const renderService: IRenderService = (this._terminal as any)._core._renderService;
9292
renderService.setRenderer((this._terminal as any)._core._createRenderer());
9393
renderService.handleResize(terminal.cols, terminal.rows);

0 commit comments

Comments
 (0)