From 868fc7ec2954b4529b0dc5e80688a753c8955a23 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 24 Sep 2022 14:44:13 -0700 Subject: [PATCH] Allow loading canvas before open --- addons/xterm-addon-canvas/src/CanvasAddon.ts | 26 +++++++++++--------- addons/xterm-addon-webgl/src/WebglAddon.ts | 15 +++++------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/addons/xterm-addon-canvas/src/CanvasAddon.ts b/addons/xterm-addon-canvas/src/CanvasAddon.ts index 9fca00a6..32fe242e 100644 --- a/addons/xterm-addon-canvas/src/CanvasAddon.ts +++ b/addons/xterm-addon-canvas/src/CanvasAddon.ts @@ -14,21 +14,23 @@ export class CanvasAddon implements ITerminalAddon { private _renderer?: CanvasRenderer; public activate(terminal: Terminal): void { + const core = (terminal as any)._core; if (!terminal.element) { - throw new Error('Cannot activate CanvasAddon before Terminal.open'); + core.onWillOpen(() => this.activate(terminal)); + return; } this._terminal = terminal; - const bufferService: IBufferService = (terminal as any)._core._bufferService; - const renderService: IRenderService = (terminal as any)._core._renderService; - const characterJoinerService: ICharacterJoinerService = (terminal as any)._core._characterJoinerService; - const charSizeService: ICharSizeService = (terminal as any)._core._charSizeService; - const coreService: ICoreService = (terminal as any)._core.coreService; - const coreBrowserService: ICoreBrowserService = (terminal as any)._core._coreBrowserService; - const decorationService: IDecorationService = (terminal as any)._core._decorationService; - const optionsService: IOptionsService = (terminal as any)._core.optionsService; - const colors: IColorSet = (terminal as any)._core._colorManager.colors; - const screenElement: HTMLElement = (terminal as any)._core.screenElement; - const linkifier = (terminal as any)._core.linkifier2; + const bufferService: IBufferService = core._bufferService; + const renderService: IRenderService = core._renderService; + const characterJoinerService: ICharacterJoinerService = core._characterJoinerService; + const charSizeService: ICharSizeService = core._charSizeService; + const coreService: ICoreService = core.coreService; + const coreBrowserService: ICoreBrowserService = core._coreBrowserService; + const decorationService: IDecorationService = core._decorationService; + const optionsService: IOptionsService = core.optionsService; + const colors: IColorSet = core._colorManager.colors; + const screenElement: HTMLElement = core.screenElement; + const linkifier = core.linkifier2; this._renderer = new CanvasRenderer(colors, screenElement, linkifier, bufferService, charSizeService, optionsService, characterJoinerService, coreService, coreBrowserService, decorationService); renderService.setRenderer(this._renderer); renderService.onResize(bufferService.cols, bufferService.rows); diff --git a/addons/xterm-addon-webgl/src/WebglAddon.ts b/addons/xterm-addon-webgl/src/WebglAddon.ts index a2441a2a..e8fa8799 100644 --- a/addons/xterm-addon-webgl/src/WebglAddon.ts +++ b/addons/xterm-addon-webgl/src/WebglAddon.ts @@ -25,20 +25,21 @@ export class WebglAddon implements ITerminalAddon { ) {} public activate(terminal: Terminal): void { + const core = (terminal as any)._core; if (!terminal.element) { - (terminal as any)._core.onWillOpen(() => this.activate(terminal)); + core.onWillOpen(() => this.activate(terminal)); return; } if (isSafari) { throw new Error('Webgl is not currently supported on Safari'); } this._terminal = terminal; - const renderService: IRenderService = (terminal as any)._core._renderService; - const characterJoinerService: ICharacterJoinerService = (terminal as any)._core._characterJoinerService; - const coreBrowserService: ICoreBrowserService = (terminal as any)._core._coreBrowserService; - const coreService: ICoreService = (terminal as any)._core.coreService; - const decorationService: IDecorationService = (terminal as any)._core._decorationService; - const colors: IColorSet = (terminal as any)._core._colorManager.colors; + const renderService: IRenderService = core._renderService; + const characterJoinerService: ICharacterJoinerService = core._characterJoinerService; + const coreBrowserService: ICoreBrowserService = core._coreBrowserService; + const coreService: ICoreService = core.coreService; + const decorationService: IDecorationService = core._decorationService; + const colors: IColorSet = core._colorManager.colors; this._renderer = new WebglRenderer(terminal, colors, characterJoinerService, coreBrowserService, coreService, decorationService, this._preserveDrawingBuffer); forwardEvent(this._renderer.onContextLoss, this._onContextLoss); forwardEvent(this._renderer.onChangeTextureAtlas, this._onChangeTextureAtlas);