diff --git a/src/Terminal.ts b/src/Terminal.ts index a18bb209..35b97bf1 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -23,8 +23,6 @@ import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminalOptions, ITerminal, IBrowser, ILinkifier, ILinkMatcherOptions, CustomKeyEventHandler, LinkMatcherHandler, IMouseZoneManager } from './Types'; import { IRenderer, CharacterJoinerHandler } from 'browser/renderer/Types'; -import { BufferSet } from 'common/buffer/BufferSet'; -import { Buffer } from 'common/buffer/Buffer'; import { CompositionHelper } from './CompositionHelper'; import { EventEmitter } from 'common/EventEmitter'; import { Viewport } from './Viewport'; @@ -56,6 +54,7 @@ import { OptionsService } from 'common/services/OptionsService'; import { ICharSizeService } from 'browser/services/Services'; import { CharSizeService } from 'browser/services/CharSizeService'; import { BufferService, MINIMUM_COLS, MINIMUM_ROWS } from 'common/services/BufferService'; +import { IBufferSet, IBuffer } from '../out/common/buffer/Types'; // Let it work inside Node.js for automated testing purposes. const document = (typeof window !== 'undefined') ? window.document : null; @@ -174,7 +173,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II public soundManager: SoundManager; public selectionManager: SelectionManager; public linkifier: ILinkifier; - public buffers: BufferSet; public viewport: IViewport; private _compositionHelper: ICompositionHelper; private _mouseZoneManager: IMouseZoneManager; @@ -312,8 +310,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II this._mouseZoneManager = this._mouseZoneManager || null; this.soundManager = this.soundManager || new SoundManager(this); - // Create the terminal's buffers and set the current buffer - this.buffers = new BufferSet(this.optionsService, this._bufferService); if (this.selectionManager) { this.selectionManager.clearSelection(); this.selectionManager.initBuffersListeners(); @@ -327,10 +323,14 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II /** * Convenience property to active buffer. */ - public get buffer(): Buffer { + public get buffer(): IBuffer { return this.buffers.active; } + public get buffers(): IBufferSet { + return this._bufferService.buffers; + } + /** * back_color_erase feature for xterm. */ diff --git a/src/TestUtils.test.ts b/src/TestUtils.test.ts index bbe09508..79e36a6d 100644 --- a/src/TestUtils.test.ts +++ b/src/TestUtils.test.ts @@ -305,6 +305,10 @@ export class MockInputHandlingTerminal implements IInputHandlingTerminal { } export class MockBuffer implements IBuffer { + markers: IMarker[]; + addMarker(y: number): IMarker { + throw new Error('Method not implemented.'); + } isCursorInViewport: boolean; lines: ICircularList; ydisp: number; diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index 0a0cb6a4..358fdb17 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -7,8 +7,11 @@ import { IBufferService, IOptionsService, ITerminalOptions, IPartialTerminalOpti import { IEvent, EventEmitter2 } from 'common/EventEmitter2'; import { clone } from 'common/Clone'; import { DEFAULT_OPTIONS } from 'common/services/OptionsService'; +import { IBufferSet, IBuffer } from './buffer/Types'; export class MockBufferService implements IBufferService { + public buffer: IBuffer = {} as any; + public buffers: IBufferSet = {} as any; constructor( public cols: number, public rows: number diff --git a/src/common/buffer/Types.ts b/src/common/buffer/Types.ts index 37ce2b7e..19794c38 100644 --- a/src/common/buffer/Types.ts +++ b/src/common/buffer/Types.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { IAttributeData, ICircularList, IBufferLine, ICellData } from 'common/Types'; +import { IAttributeData, ICircularList, IBufferLine, ICellData, IMarker } from 'common/Types'; import { IEvent } from 'common/EventEmitter2'; // BufferIndex denotes a position in the buffer: [rowIndex, colIndex] @@ -33,6 +33,7 @@ export interface IBuffer { savedX: number; savedCurAttrData: IAttributeData; isCursorInViewport: boolean; + markers: IMarker[]; translateBufferLineToString(lineIndex: number, trimRight: boolean, startCol?: number, endCol?: number): string; getWrappedRangeForLine(y: number): { first: number, last: number }; nextStop(x?: number): number; @@ -42,6 +43,7 @@ export interface IBuffer { iterator(trimRight: boolean, startIndex?: number, endIndex?: number, startOverscan?: number, endOverscan?: number): IBufferStringIterator; getNullCell(attr?: IAttributeData): ICellData; getWhitespaceCell(attr?: IAttributeData): ICellData; + addMarker(y: number): IMarker; } export interface IBufferSet { @@ -53,4 +55,6 @@ export interface IBufferSet { activateNormalBuffer(): void; activateAltBuffer(fillAttr?: IAttributeData): void; + resize(newCols: number, newRows: number): void; + setupTabStops(i?: number): void; } diff --git a/src/common/services/BufferService.ts b/src/common/services/BufferService.ts index 542166c1..bbac7803 100644 --- a/src/common/services/BufferService.ts +++ b/src/common/services/BufferService.ts @@ -3,7 +3,9 @@ * @license MIT */ -import { IBufferService, IOptionsService } from './Services'; +import { IBufferService, IOptionsService } from 'common/services/Services'; +import { BufferSet } from 'common/buffer/BufferSet'; +import { IBufferSet, IBuffer } from 'common/buffer/Types'; export const MINIMUM_COLS = 2; // Less than 2 can mess with wide chars export const MINIMUM_ROWS = 1; @@ -11,12 +13,16 @@ export const MINIMUM_ROWS = 1; export class BufferService implements IBufferService { public cols: number; public rows: number; + public buffers: IBufferSet; + + public get buffer(): IBuffer { return this.buffers.active; } constructor( optionsService: IOptionsService ) { this.cols = Math.max(optionsService.options.cols, MINIMUM_COLS); this.rows = Math.max(optionsService.options.rows, MINIMUM_ROWS); + this.buffers = new BufferSet(optionsService, this); } public resize(cols: number, rows: number): void { diff --git a/src/common/services/Services.d.ts b/src/common/services/Services.d.ts index 8ebc0308..0da78fc7 100644 --- a/src/common/services/Services.d.ts +++ b/src/common/services/Services.d.ts @@ -4,10 +4,13 @@ */ import { IEvent } from 'common/EventEmitter2'; +import { IBuffer, IBufferSet } from 'common/buffer/Types'; export interface IBufferService { readonly cols: number; readonly rows: number; + readonly buffer: IBuffer; + readonly buffers: IBufferSet; // TODO: Move resize event here