Use options service in renderers

This commit is contained in:
Daniel Imms
2022-10-09 10:57:49 -07:00
parent 8d7137417b
commit a37ea14d10
13 changed files with 20 additions and 44 deletions
@@ -79,7 +79,6 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
}
}
public handleOptionsChanged(): void {}
public handleBlur(): void {}
public handleFocus(): void {}
public handleCursorMove(): void {}
+1 -1
View File
@@ -24,7 +24,6 @@ export class CanvasAddon extends Disposable implements ITerminalAddon {
public activate(terminal: Terminal): void {
const core = (terminal as any)._core as ITerminal;
const unsafeCore = core as any;
if (!terminal.element) {
this.register(core.onWillOpen(() => this.activate(terminal)));
return;
@@ -36,6 +35,7 @@ export class CanvasAddon extends Disposable implements ITerminalAddon {
const screenElement = core.screenElement!;
const linkifier = core.linkifier2;
const unsafeCore = core as any;
const bufferService: IBufferService = unsafeCore._bufferService;
const renderService: IRenderService = unsafeCore._renderService;
const characterJoinerService: ICharacterJoinerService = unsafeCore._characterJoinerService;
@@ -68,10 +68,6 @@ export class CanvasRenderer extends Disposable implements IRenderer {
this._updateDimensions();
this.register(observeDevicePixelDimensions(this._renderLayers[0].canvas, this._coreBrowserService.window, (w, h) => this._setCanvasDevicePixelDimensions(w, h)));
this.handleOptionsChanged();
this.register(this._optionsService.onOptionChange(() => this.handleOptionsChanged()));
this.register(toDisposable(() => {
for (const l of this._renderLayers) {
l.dispose();
@@ -131,10 +127,6 @@ export class CanvasRenderer extends Disposable implements IRenderer {
this._runOperation(l => l.handleCursorMove());
}
public handleOptionsChanged(): void {
this._runOperation(l => l.handleOptionsChanged());
}
public clear(): void {
this._runOperation(l => l.reset());
}
@@ -58,6 +58,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
'block': this._renderBlockCursor.bind(this),
'underline': this._renderUnderlineCursor.bind(this)
};
this.register(optionsService.onOptionChange(() => this._handleOptionsChanged()));
this.register(toDisposable(() => {
this._cursorBlinkStateManager?.dispose();
this._cursorBlinkStateManager = undefined;
@@ -79,7 +80,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
public reset(): void {
this._clearCursor();
this._cursorBlinkStateManager?.restartBlinkAnimation();
this.handleOptionsChanged();
this._handleOptionsChanged();
}
public handleBlur(): void {
@@ -92,7 +93,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
}
public handleOptionsChanged(): void {
private _handleOptionsChanged(): void {
if (this._optionsService.rawOptions.cursorBlink) {
if (!this._cursorBlinkStateManager) {
this._cursorBlinkStateManager = new CursorBlinkStateManager(this._coreBrowserService.isFocused, () => {
@@ -45,6 +45,7 @@ export class TextRenderLayer extends BaseRenderLayer {
) {
super(terminal, container, 'text', zIndex, alpha, themeService, bufferService, optionsService, decorationService, coreBrowserService);
this._state = new GridCache<CharData>();
this.register(optionsService.onSpecificOptionChange('allowTransparency', value => this._setTransparency(value)));
}
public resize(dim: IRenderDimensions): void {
@@ -251,10 +252,6 @@ export class TextRenderLayer extends BaseRenderLayer {
this._drawForeground(firstRow, lastRow);
}
public handleOptionsChanged(): void {
this._setTransparency(this._optionsService.rawOptions.allowTransparency);
}
/**
* Whether a character is overlapping to the next cell.
*/
-5
View File
@@ -73,11 +73,6 @@ export interface IRenderLayer extends IDisposable {
*/
handleCursorMove(): void;
/**
* Called when options change.
*/
handleOptionsChanged(): void;
/**
* Called when the data in the grid has changed (or needs to be rendered
* again).
+2 -2
View File
@@ -34,9 +34,8 @@ export class WebglAddon extends Disposable implements ITerminalAddon {
}
const core = (terminal as any)._core as ITerminal;
const unsafeCore = core as any;
if (!terminal.element) {
this.register(unsafeCore.onWillOpen(() => this.activate(terminal)));
this.register(core.onWillOpen(() => this.activate(terminal)));
return;
}
@@ -44,6 +43,7 @@ export class WebglAddon extends Disposable implements ITerminalAddon {
const coreService: ICoreService = core.coreService;
const optionsService: IOptionsService = core.optionsService;
const unsafeCore = core as any;
const renderService: IRenderService = unsafeCore._renderService;
const characterJoinerService: ICharacterJoinerService = unsafeCore._characterJoinerService;
const coreBrowserService: ICoreBrowserService = unsafeCore._coreBrowserService;
@@ -73,7 +73,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
this._renderLayers = [
new LinkRenderLayer(this._core.screenElement!, 2, this._terminal, this._core.linkifier2, this._coreBrowserService, this._themeService),
new CursorRenderLayer(_terminal, this._core.screenElement!, 3, this._onRequestRedraw, this._coreBrowserService, coreService, this._themeService)
new CursorRenderLayer(_terminal, this._core.screenElement!, 3, this._onRequestRedraw, this._coreBrowserService, coreService, this._themeService, optionsService)
];
this.dimensions = {
scaledCharWidth: 0,
@@ -91,7 +91,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
};
this._devicePixelRatio = this._coreBrowserService.dpr;
this._updateDimensions();
this.register(optionsService.onOptionChange(() => this.handleOptionsChanged()));
this.register(optionsService.onOptionChange(() => this._handleOptionsChanged()));
this._canvas = document.createElement('canvas');
@@ -232,10 +232,7 @@ export class WebglRenderer extends Disposable implements IRenderer {
}
}
public handleOptionsChanged(): void {
for (const l of this._renderLayers) {
l.handleOptionsChanged(this._terminal);
}
private _handleOptionsChanged(): void {
this._updateDimensions();
this._refreshCharAtlas();
}
@@ -59,7 +59,6 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
}
}
public handleOptionsChanged(terminal: Terminal): void {}
public handleBlur(terminal: Terminal): void {}
public handleFocus(terminal: Terminal): void {}
public handleCursorMove(terminal: Terminal): void {}
@@ -11,7 +11,7 @@ import { IColorSet, ReadonlyColorSet } from 'browser/Types';
import { IRenderDimensions, IRequestRedrawEvent } from 'browser/renderer/shared/Types';
import { IEventEmitter } from 'common/EventEmitter';
import { ICoreBrowserService, IThemeService } from 'browser/services/Services';
import { ICoreService } from 'common/services/Services';
import { ICoreService, IOptionsService } from 'common/services/Services';
import { toDisposable } from 'common/Lifecycle';
interface ICursorState {
@@ -40,7 +40,8 @@ export class CursorRenderLayer extends BaseRenderLayer {
private _onRequestRefreshRowsEvent: IEventEmitter<IRequestRedrawEvent>,
coreBrowserService: ICoreBrowserService,
private readonly _coreService: ICoreService,
themeService: IThemeService
themeService: IThemeService,
optionsService: IOptionsService
) {
super(terminal, container, 'cursor', zIndex, true, coreBrowserService, themeService);
this._state = {
@@ -55,7 +56,8 @@ export class CursorRenderLayer extends BaseRenderLayer {
'block': this._renderBlockCursor.bind(this),
'underline': this._renderUnderlineCursor.bind(this)
};
this.handleOptionsChanged(terminal);
this._handleOptionsChanged(terminal);
this.register(optionsService.onOptionChange(() => this._handleOptionsChanged(terminal)));
this.register(toDisposable(() => {
this._cursorBlinkStateManager?.dispose();
this._cursorBlinkStateManager = undefined;
@@ -77,7 +79,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
public reset(terminal: Terminal): void {
this._clearCursor();
this._cursorBlinkStateManager?.restartBlinkAnimation(terminal);
this.handleOptionsChanged(terminal);
this._handleOptionsChanged(terminal);
}
public handleBlur(terminal: Terminal): void {
@@ -90,7 +92,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
this._onRequestRefreshRowsEvent.fire({ start: terminal.buffer.active.cursorY, end: terminal.buffer.active.cursorY });
}
public handleOptionsChanged(terminal: Terminal): void {
private _handleOptionsChanged(terminal: Terminal): void {
if (terminal.options.cursorBlink) {
if (!this._cursorBlinkStateManager) {
this._cursorBlinkStateManager = new CursorBlinkStateManager(() => {
@@ -7,7 +7,7 @@ import { is256Color } from 'browser/renderer/shared/CharAtlasUtils';
import { INVERTED_DEFAULT_COLOR } from 'browser/renderer/shared/Constants';
import { IRenderDimensions } from 'browser/renderer/shared/Types';
import { ICoreBrowserService, IThemeService } from 'browser/services/Services';
import { ILinkifier2, ILinkifierEvent, ITerminal } from 'browser/Types';
import { ILinkifier2, ILinkifierEvent } from 'browser/Types';
import { Terminal } from 'xterm';
import { BaseRenderLayer } from './BaseRenderLayer';
@@ -4,7 +4,6 @@
*/
import { IDisposable, Terminal } from 'xterm';
import { IColorSet, ReadonlyColorSet } from 'browser/Types';
import { IRenderDimensions } from 'browser/renderer/shared/Types';
export interface IRenderLayer extends IDisposable {
@@ -23,11 +22,6 @@ export interface IRenderLayer extends IDisposable {
*/
handleCursorMove(terminal: Terminal): void;
/**
* Called when options change.
*/
handleOptionsChanged(terminal: Terminal): void;
/**
* Called when the data in the grid has changed (or needs to be rendered
* again).
+2 -2
View File
@@ -79,7 +79,7 @@ export class DomRenderer extends Disposable implements IRenderer {
actualCellHeight: 0
};
this._updateDimensions();
this.register(this._optionsService.onOptionChange(() => this.handleOptionsChanged()));
this.register(this._optionsService.onOptionChange(() => this._handleOptionsChanged()));
this.register(themeService.onChangeColors(e => this._injectCss(e)));
this._injectCss(themeService.colors);
@@ -343,7 +343,7 @@ export class DomRenderer extends Disposable implements IRenderer {
// No-op, the cursor is drawn when rows are drawn
}
public handleOptionsChanged(): void {
private _handleOptionsChanged(): void {
// Force a refresh
this._updateDimensions();
}