From 60ae9add3f214fee997d230409bdaa8e5a0c213a Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 14 Jul 2019 11:48:44 -0700 Subject: [PATCH] Remove most terminal refs from BaseRenderLayer --- src/renderer/BaseRenderLayer.ts | 17 ++++++++++------- src/renderer/CursorRenderLayer.ts | 6 +++--- src/renderer/LinkRenderLayer.ts | 13 +++++++++++-- src/renderer/Renderer.ts | 6 +++--- src/renderer/SelectionRenderLayer.ts | 7 ++++--- src/renderer/TextRenderLayer.ts | 14 ++++++++++++-- 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index c0df47dc..929651fa 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -15,6 +15,7 @@ import { acquireCharAtlas } from 'browser/renderer/atlas/CharAtlasCache'; import { AttributeData } from 'common/buffer/AttributeData'; import { IColorSet } from 'browser/Types'; import { CellData } from 'common/buffer/CellData'; +import { IBufferService, IOptionsService } from 'common/services/Services'; export abstract class BaseRenderLayer implements IRenderLayer { private _canvas: HTMLCanvasElement; @@ -47,7 +48,9 @@ export abstract class BaseRenderLayer implements IRenderLayer { zIndex: number, private _alpha: boolean, protected _colors: IColorSet, - protected _terminal: ITerminal + protected _terminal: ITerminal, + protected readonly _bufferService: IBufferService, + protected readonly _optionsService: IOptionsService ) { this._canvas = document.createElement('canvas'); this._canvas.classList.add(`xterm-${id}-layer`); @@ -98,7 +101,7 @@ export abstract class BaseRenderLayer implements IRenderLayer { // Regenerate char atlas and force a full redraw this._refreshCharAtlas(this._colors); - this.onGridChanged(0, this._terminal.rows - 1); + this.onGridChanged(0, this._bufferService.rows - 1); } /** @@ -282,7 +285,7 @@ export abstract class BaseRenderLayer implements IRenderLayer { fg = (cell.isFgDefault()) ? DEFAULT_COLOR : cell.getFgColor(); } - const drawInBrightColor = this._terminal.options.drawBoldTextInBrightColors && cell.isBold() && fg < 8 && fg !== INVERTED_DEFAULT_COLOR; + const drawInBrightColor = this._optionsService.options.drawBoldTextInBrightColors && cell.isBold() && fg < 8 && fg !== INVERTED_DEFAULT_COLOR; fg += drawInBrightColor ? 8 : 0; this._currentGlyphIdentifier.chars = cell.getChars() || WHITESPACE_CELL_CHAR; @@ -334,7 +337,7 @@ export abstract class BaseRenderLayer implements IRenderLayer { this._ctx.fillStyle = `rgb(${AttributeData.toColorRGB(cell.getFgColor()).join(',')})`; } else { let fg = cell.getFgColor(); - if (this._terminal.options.drawBoldTextInBrightColors && cell.isBold() && fg < 8) { + if (this._optionsService.options.drawBoldTextInBrightColors && cell.isBold() && fg < 8) { fg += 8; } this._ctx.fillStyle = this._colors.ansi[fg].css; @@ -364,7 +367,7 @@ export abstract class BaseRenderLayer implements IRenderLayer { this._ctx.rect( 0, y * this._scaledCellHeight, - this._terminal.cols * this._scaledCellWidth, + this._bufferService.cols * this._scaledCellWidth, this._scaledCellHeight); this._ctx.clip(); } @@ -374,10 +377,10 @@ export abstract class BaseRenderLayer implements IRenderLayer { * @param isBold If we should use the bold fontWeight. */ protected _getFont(isBold: boolean, isItalic: boolean): string { - const fontWeight = isBold ? this._terminal.options.fontWeightBold : this._terminal.options.fontWeight; + const fontWeight = isBold ? this._optionsService.options.fontWeightBold : this._optionsService.options.fontWeight; const fontStyle = isItalic ? 'italic' : ''; - return `${fontStyle} ${fontWeight} ${this._terminal.options.fontSize * window.devicePixelRatio}px ${this._terminal.options.fontFamily}`; + return `${fontStyle} ${fontWeight} ${this._optionsService.options.fontSize * window.devicePixelRatio}px ${this._optionsService.options.fontFamily}`; } } diff --git a/src/renderer/CursorRenderLayer.ts b/src/renderer/CursorRenderLayer.ts index 26e5e4ac..57f7bcd5 100644 --- a/src/renderer/CursorRenderLayer.ts +++ b/src/renderer/CursorRenderLayer.ts @@ -35,10 +35,10 @@ export class CursorRenderLayer extends BaseRenderLayer { zIndex: number, colors: IColorSet, terminal: ITerminal, - private readonly _bufferService: IBufferService, - private readonly _optionsService: IOptionsService + readonly bufferService: IBufferService, + readonly optionsService: IOptionsService ) { - super(container, 'cursor', zIndex, true, colors, terminal); + super(container, 'cursor', zIndex, true, colors, terminal, bufferService, optionsService); this._state = { x: null, y: null, diff --git a/src/renderer/LinkRenderLayer.ts b/src/renderer/LinkRenderLayer.ts index b57abaab..f225f745 100644 --- a/src/renderer/LinkRenderLayer.ts +++ b/src/renderer/LinkRenderLayer.ts @@ -9,12 +9,21 @@ import { BaseRenderLayer } from './BaseRenderLayer'; import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/atlas/Constants'; import { is256Color } from 'browser/renderer/atlas/CharAtlasUtils'; import { IColorSet, ILinkifierEvent, ILinkifier } from 'browser/Types'; +import { IBufferService, IOptionsService } from 'common/services/Services'; export class LinkRenderLayer extends BaseRenderLayer { private _state: ILinkifierEvent = null; - constructor(container: HTMLElement, zIndex: number, colors: IColorSet, terminal: ITerminal, linkifier: ILinkifier) { - super(container, 'link', zIndex, true, colors, terminal); + constructor( + container: HTMLElement, + zIndex: number, + colors: IColorSet, + terminal: ITerminal, + linkifier: ILinkifier, + readonly bufferService: IBufferService, + readonly optionsService: IOptionsService + ) { + super(container, 'link', zIndex, true, colors, terminal, bufferService, optionsService); linkifier.onLinkHover(e => this._onLinkHover(e)); linkifier.onLinkLeave(e => this._onLinkLeave(e)); } diff --git a/src/renderer/Renderer.ts b/src/renderer/Renderer.ts index 090cc8e8..03c44817 100644 --- a/src/renderer/Renderer.ts +++ b/src/renderer/Renderer.ts @@ -35,9 +35,9 @@ export class Renderer extends Disposable implements IRenderer { this._characterJoinerRegistry = new CharacterJoinerRegistry(bufferService); this._renderLayers = [ - new TextRenderLayer(this._terminal.screenElement, 0, this._colors, this._characterJoinerRegistry, allowTransparency, this._terminal), - new SelectionRenderLayer(this._terminal.screenElement, 1, this._colors, this._terminal, bufferService), - new LinkRenderLayer(this._terminal.screenElement, 2, this._colors, this._terminal, this._terminal.linkifier), + new TextRenderLayer(this._terminal.screenElement, 0, this._colors, this._characterJoinerRegistry, allowTransparency, this._terminal, bufferService, optionsService), + new SelectionRenderLayer(this._terminal.screenElement, 1, this._colors, this._terminal, bufferService, optionsService), + new LinkRenderLayer(this._terminal.screenElement, 2, this._colors, this._terminal, this._terminal.linkifier, bufferService, optionsService), new CursorRenderLayer(this._terminal.screenElement, 3, this._colors, this._terminal, bufferService, optionsService) ]; this.dimensions = { diff --git a/src/renderer/SelectionRenderLayer.ts b/src/renderer/SelectionRenderLayer.ts index 233c4020..97a38645 100644 --- a/src/renderer/SelectionRenderLayer.ts +++ b/src/renderer/SelectionRenderLayer.ts @@ -7,7 +7,7 @@ import { ITerminal } from '../Types'; import { IRenderDimensions } from 'browser/renderer/Types'; import { BaseRenderLayer } from './BaseRenderLayer'; import { IColorSet } from 'browser/Types'; -import { IBufferService } from 'common/services/Services'; +import { IBufferService, IOptionsService } from 'common/services/Services'; interface ISelectionState { start: [number, number]; @@ -24,9 +24,10 @@ export class SelectionRenderLayer extends BaseRenderLayer { zIndex: number, colors: IColorSet, terminal: ITerminal, - private readonly _bufferService: IBufferService + readonly bufferService: IBufferService, + readonly optionsService: IOptionsService ) { - super(container, 'selection', zIndex, true, colors, terminal); + super(container, 'selection', zIndex, true, colors, terminal, bufferService, optionsService); this._clearState(); } diff --git a/src/renderer/TextRenderLayer.ts b/src/renderer/TextRenderLayer.ts index b1e59451..e3035e97 100644 --- a/src/renderer/TextRenderLayer.ts +++ b/src/renderer/TextRenderLayer.ts @@ -13,6 +13,7 @@ import { NULL_CELL_CODE, Content } from 'common/buffer/Constants'; import { JoinedCellData } from 'browser/renderer/CharacterJoinerRegistry'; import { IColorSet } from 'browser/Types'; import { CellData } from 'common/buffer/CellData'; +import { IOptionsService, IBufferService } from 'common/services/Services'; /** * This CharData looks like a null character, which will forc a clear and render @@ -29,8 +30,17 @@ export class TextRenderLayer extends BaseRenderLayer { private _characterJoinerRegistry: ICharacterJoinerRegistry; private _workCell = new CellData(); - constructor(container: HTMLElement, zIndex: number, colors: IColorSet, characterJoinerRegistry: ICharacterJoinerRegistry, alpha: boolean, terminal: ITerminal) { - super(container, 'text', zIndex, alpha, colors, terminal); + constructor( + container: HTMLElement, + zIndex: number, + colors: IColorSet, + characterJoinerRegistry: ICharacterJoinerRegistry, + alpha: boolean, + terminal: ITerminal, + readonly bufferService: IBufferService, + readonly optionsService: IOptionsService + ) { + super(container, 'text', zIndex, alpha, colors, terminal, bufferService, optionsService); this._state = new GridCache(); this._characterJoinerRegistry = characterJoinerRegistry; }