Allow renderer to be swapped in and out at runtime

Fixes #1589
This commit is contained in:
Daniel Imms
2018-07-29 13:50:45 -07:00
parent 6691f80906
commit 5aaf9ef11b
7 changed files with 62 additions and 12 deletions
+4
View File
@@ -36,6 +36,10 @@ export abstract class BaseRenderLayer implements IRenderLayer {
this._container.appendChild(this._canvas);
}
public dispose(): void {
this._container.removeChild(this._canvas);
}
private _initCanvas(): void {
this._ctx = this._canvas.getContext('2d', {alpha: this._alpha});
// Draw the background if this is an opaque layer
+5
View File
@@ -76,6 +76,11 @@ export class Renderer extends EventEmitter implements IRenderer {
}
}
public dispose(): void {
super.dispose();
this._renderLayers.forEach(l => l.dispose());
}
public onIntersectionChange(entry: IntersectionObserverEntry): void {
this._isPaused = entry.intersectionRatio === 0;
if (!this._isPaused && this._needsFullRefresh) {
+1 -1
View File
@@ -66,7 +66,7 @@ export interface IRenderDimensions {
actualCellHeight: number;
}
export interface IRenderLayer {
export interface IRenderLayer extends IDisposable {
/**
* Called when the terminal loses focus.
*/
+9
View File
@@ -81,6 +81,15 @@ export class DomRenderer extends EventEmitter implements IRenderer {
this._terminal.screenElement.appendChild(this._selectionContainer);
}
public dispose(): void {
this._terminal.element.classList.remove(TERMINAL_CLASS_PREFIX + this._terminalClass);
this._terminal.screenElement.removeChild(this._rowContainer);
this._terminal.screenElement.removeChild(this._selectionContainer);
this._terminal.screenElement.removeChild(this._themeStyleElement);
this._terminal.screenElement.removeChild(this._dimensionsStyleElement);
super.dispose();
}
private _updateDimensions(): void {
this.dimensions.scaledCharWidth = this._terminal.charMeasure.width * window.devicePixelRatio;
this.dimensions.scaledCharHeight = this._terminal.charMeasure.height * window.devicePixelRatio;