From 8d7137417bc8200cab8bfb6eef9038dcddce7700 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sun, 9 Oct 2022 10:12:19 -0700 Subject: [PATCH] Split renderer safe vs unsafe api on activate --- addons/xterm-addon-canvas/src/CanvasAddon.ts | 26 +++++++++++--------- addons/xterm-addon-webgl/src/WebglAddon.ts | 21 ++++++++++------ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/addons/xterm-addon-canvas/src/CanvasAddon.ts b/addons/xterm-addon-canvas/src/CanvasAddon.ts index 1dc607e5..74248f1c 100644 --- a/addons/xterm-addon-canvas/src/CanvasAddon.ts +++ b/addons/xterm-addon-canvas/src/CanvasAddon.ts @@ -4,7 +4,7 @@ */ import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services'; -import { IColorSet } from 'browser/Types'; +import { IColorSet, ITerminal } from 'browser/Types'; import { CanvasRenderer } from './CanvasRenderer'; import { IBufferService, ICoreService, IDecorationService, IOptionsService } from 'common/services/Services'; import { ITerminalAddon, Terminal } from 'xterm'; @@ -23,25 +23,27 @@ export class CanvasAddon extends Disposable implements ITerminalAddon { } public activate(terminal: Terminal): void { - const core = (terminal as any)._core; + const core = (terminal as any)._core as ITerminal; + const unsafeCore = core as any; if (!terminal.element) { this.register(core.onWillOpen(() => this.activate(terminal))); return; } this._terminal = terminal; - 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 themeService: IThemeService = core._themeService; - const screenElement: HTMLElement = core.screenElement; + const coreService = core.coreService; + const optionsService = core.optionsService; + const screenElement = core.screenElement!; const linkifier = core.linkifier2; + const bufferService: IBufferService = unsafeCore._bufferService; + const renderService: IRenderService = unsafeCore._renderService; + const characterJoinerService: ICharacterJoinerService = unsafeCore._characterJoinerService; + const charSizeService: ICharSizeService = unsafeCore._charSizeService; + const coreBrowserService: ICoreBrowserService = unsafeCore._coreBrowserService; + const decorationService: IDecorationService = unsafeCore._decorationService; + const themeService: IThemeService = unsafeCore._themeService; + this._renderer = new CanvasRenderer(terminal, screenElement, linkifier, bufferService, charSizeService, optionsService, characterJoinerService, coreService, coreBrowserService, decorationService, themeService); this.register(forwardEvent(this._renderer.onChangeTextureAtlas, this._onChangeTextureAtlas)); renderService.setRenderer(this._renderer); diff --git a/addons/xterm-addon-webgl/src/WebglAddon.ts b/addons/xterm-addon-webgl/src/WebglAddon.ts index 295db320..149a93d7 100644 --- a/addons/xterm-addon-webgl/src/WebglAddon.ts +++ b/addons/xterm-addon-webgl/src/WebglAddon.ts @@ -4,10 +4,12 @@ */ import { ICharacterJoinerService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services'; +import { ITerminal } from 'browser/Types'; import { EventEmitter, forwardEvent } from 'common/EventEmitter'; import { Disposable, toDisposable } from 'common/Lifecycle'; import { isSafari } from 'common/Platform'; import { ICoreService, IDecorationService, IOptionsService } from 'common/services/Services'; +import { ICoreTerminal } from 'common/Types'; import { ITerminalAddon, Terminal } from 'xterm'; import { WebglRenderer } from './WebglRenderer'; @@ -30,19 +32,24 @@ export class WebglAddon extends Disposable implements ITerminalAddon { if (isSafari) { throw new Error('Webgl is not currently supported on Safari'); } - const core = (terminal as any)._core; + + const core = (terminal as any)._core as ITerminal; + const unsafeCore = core as any; if (!terminal.element) { - this.register(core.onWillOpen(() => this.activate(terminal))); + this.register(unsafeCore.onWillOpen(() => this.activate(terminal))); return; } + this._terminal = terminal; - 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 themeService: IThemeService = core._themeService; const optionsService: IOptionsService = core.optionsService; + + const renderService: IRenderService = unsafeCore._renderService; + const characterJoinerService: ICharacterJoinerService = unsafeCore._characterJoinerService; + const coreBrowserService: ICoreBrowserService = unsafeCore._coreBrowserService; + const decorationService: IDecorationService = unsafeCore._decorationService; + const themeService: IThemeService = unsafeCore._themeService; + this._renderer = this.register(new WebglRenderer(terminal, themeService, characterJoinerService, coreBrowserService, optionsService, coreService, decorationService, this._preserveDrawingBuffer)); this.register(forwardEvent(this._renderer.onContextLoss, this._onContextLoss)); this.register(forwardEvent(this._renderer.onChangeTextureAtlas, this._onChangeTextureAtlas));