From 3a1a0d659069e5abbaf060da3f1f2f6f930ded88 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sun, 26 Apr 2020 06:34:36 -0700 Subject: [PATCH] Remove input handler Terminal.resize dep --- src/InputHandler.ts | 4 ++-- src/Terminal.ts | 21 ++++++--------------- src/Types.d.ts | 1 - src/browser/services/RenderService.ts | 4 ++-- src/common/CoreTerminal.ts | 13 ++++++++++++- src/common/TestUtils.test.ts | 1 + 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/InputHandler.ts b/src/InputHandler.ts index dcdabe951..de6433143 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -1741,7 +1741,7 @@ export class InputHandler extends Disposable implements IInputHandler { * through `options.windowsOptions`. */ if (this._optionsService.options.windowOptions.setWinLines) { - this._terminal.resize(132, this._bufferService.rows); + this._bufferService.resize(132, this._bufferService.rows); this._onRequestReset.fire(); } break; @@ -1968,7 +1968,7 @@ export class InputHandler extends Disposable implements IInputHandler { * through `options.windowsOptions`. */ if (this._optionsService.options.windowOptions.setWinLines) { - this._terminal.resize(80, this._bufferService.rows); + this._bufferService.resize(80, this._bufferService.rows); this._onRequestReset.fire(); } break; diff --git a/src/Terminal.ts b/src/Terminal.ts index 9572345ee..6e192320a 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -47,7 +47,6 @@ import { ColorManager } from 'browser/ColorManager'; import { RenderService } from 'browser/services/RenderService'; import { ICharSizeService, IRenderService, IMouseService, ISelectionService, ISoundService, ICoreBrowserService } from 'browser/services/Services'; import { CharSizeService } from 'browser/services/CharSizeService'; -import { MINIMUM_COLS, MINIMUM_ROWS } from 'common/services/BufferService'; import { IBuffer } from 'common/buffer/Types'; import { MouseService } from 'browser/services/MouseService'; import { IParams, IFunctionIdentifier } from 'common/parser/Types'; @@ -155,6 +154,9 @@ export class Terminal extends CoreTerminal implements ITerminal, IInputHandlingT this._setup(); + // Setup listeners + this._bufferService.onResize(e => this._afterResize(e.cols, e.rows)); + this._writeBuffer = new WriteBuffer(data => this._inputHandler.parse(data)); } @@ -1275,10 +1277,6 @@ export class Terminal extends CoreTerminal implements ITerminal, IInputHandlingT * @param y The number of rows to resize to. */ public resize(x: number, y: number): void { - if (isNaN(x) || isNaN(y)) { - return; - } - if (x === this.cols && y === this.rows) { // Check if we still need to measure the char size (fixes #785). if (this._charSizeService && !this._charSizeService.hasValidSize) { @@ -1287,22 +1285,15 @@ export class Terminal extends CoreTerminal implements ITerminal, IInputHandlingT return; } - x = Math.max(x, MINIMUM_COLS); - y = Math.max(y, MINIMUM_ROWS); - - this._bufferService.resize(x, y); - - // TODO: Have charsize, viewport and renderservice depend on IBufferService.onResize? + super.resize(x, y); + } + private _afterResize(x: number, y: number): void { this._charSizeService?.measure(); - // TODO: Call on resize event? // Sync the scroll area to make sure scroll events don't fire and scroll the viewport to an // invalid location this.viewport?.syncScrollArea(true); - - // TODO: Move to renderservice - this.refresh(0, this.rows - 1); } /** diff --git a/src/Types.d.ts b/src/Types.d.ts index 047df8ec9..c3e1c53dd 100644 --- a/src/Types.d.ts +++ b/src/Types.d.ts @@ -24,7 +24,6 @@ export interface IInputHandlingTerminal { viewport: IViewport; is(term: string): boolean; - resize(x: number, y: number): void; } export interface ICompositionHelper { diff --git a/src/browser/services/RenderService.ts b/src/browser/services/RenderService.ts index d9aaf60ab..27b66458b 100644 --- a/src/browser/services/RenderService.ts +++ b/src/browser/services/RenderService.ts @@ -40,8 +40,7 @@ export class RenderService extends Disposable implements IRenderService { screenElement: HTMLElement, @IOptionsService optionsService: IOptionsService, @ICharSizeService charSizeService: ICharSizeService, - @IBufferService private readonly _bufferService: IBufferService, - @ICoreService private readonly _coreService: ICoreService + @IBufferService private readonly _bufferService: IBufferService ) { super(); this._renderDebouncer = new RenderDebouncer((start, end) => this._renderRows(start, end)); @@ -51,6 +50,7 @@ export class RenderService extends Disposable implements IRenderService { this._screenDprMonitor.setListener(() => this.onDevicePixelRatioChange()); this.register(this._screenDprMonitor); + this.register(this._bufferService.onResize(e => this._fullRefresh())); this.register(optionsService.onOptionChange(() => this._renderer.onOptionsChanged())); this.register(charSizeService.onCharSizeChange(() => this.onCharSizeChanged())); diff --git a/src/common/CoreTerminal.ts b/src/common/CoreTerminal.ts index 90cc7ade7..49f3509db 100644 --- a/src/common/CoreTerminal.ts +++ b/src/common/CoreTerminal.ts @@ -25,7 +25,7 @@ import { Disposable } from 'common/Lifecycle'; import { IInstantiationService, IOptionsService, IBufferService, ILogService, ICharsetService, ICoreService, ICoreMouseService, IUnicodeService, IDirtyRowService } from 'common/services/Services'; import { InstantiationService } from 'common/services/InstantiationService'; import { LogService } from 'common/services/LogService'; -import { BufferService } from 'common/services/BufferService'; +import { BufferService, MINIMUM_COLS, MINIMUM_ROWS } from 'common/services/BufferService'; import { OptionsService } from 'common/services/OptionsService'; import { ITerminalOptions, IDisposable } from './Types'; import { CoreService } from 'common/services/CoreService'; @@ -105,6 +105,17 @@ export abstract class CoreTerminal extends Disposable { this._windowsMode = undefined; } + public resize(x: number, y: number): void { + if (isNaN(x) || isNaN(y)) { + return; + } + + x = Math.max(x, MINIMUM_COLS); + y = Math.max(y, MINIMUM_ROWS); + + this._bufferService.resize(x, y); + } + protected _setup(): void { if (this.optionsService.options.windowsMode) { this._enableWindowsMode(); diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index e5b3a4258..eacf92fe8 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -16,6 +16,7 @@ export class MockBufferService implements IBufferService { public serviceBrand: any; public get buffer(): IBuffer { return this.buffers.active; } public buffers: IBufferSet = {} as any; + public onResize: IEvent<{ cols: number, rows: number }> = new EventEmitter<{ cols: number, rows: number }>().event; constructor( public cols: number, public rows: number,