From 308cf8247a694e4201b6c8d6b534f5d45145af1b Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 15 Jun 2019 23:40:31 -0700 Subject: [PATCH] Remove terminal dep in char joiner registry --- src/renderer/CharacterJoinerRegistry.test.ts | 15 ++++----------- src/renderer/CharacterJoinerRegistry.ts | 13 ++++++------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/renderer/CharacterJoinerRegistry.test.ts b/src/renderer/CharacterJoinerRegistry.test.ts index a73672a2..acc87054 100644 --- a/src/renderer/CharacterJoinerRegistry.test.ts +++ b/src/renderer/CharacterJoinerRegistry.test.ts @@ -4,24 +4,19 @@ */ import { assert } from 'chai'; - -import { MockTerminal, MockBuffer } from '../TestUtils.test'; -import { CircularList } from 'common/CircularList'; - import { ICharacterJoinerRegistry } from './Types'; import { CharacterJoinerRegistry } from './CharacterJoinerRegistry'; import { BufferLine } from 'common/buffer/BufferLine'; import { IBufferLine } from 'common/Types'; import { CellData } from 'common/buffer/CellData'; +import { MockBufferService } from 'common/TestUtils.test'; describe('CharacterJoinerRegistry', () => { let registry: ICharacterJoinerRegistry; beforeEach(() => { - const terminal = new MockTerminal(); - terminal.cols = 16; - terminal.buffer = new MockBuffer(); - const lines = new CircularList(7); + const bufferService = new MockBufferService(16, 10); + const lines = bufferService.buffer.lines; lines.set(0, lineData([['a -> b -> c -> d']])); lines.set(1, lineData([['a -> b => c -> d']])); lines.set(2, lineData([['a -> b -', 0xFFFFFFFF], ['> c -> d', 0]])); @@ -44,9 +39,7 @@ describe('CharacterJoinerRegistry', () => { for (let i = 0; i < sub.length; ++i) line6.setCell(i + oldSize, sub.loadCell(i, new CellData())); lines.set(6, line6); - (terminal.buffer).setLines(lines); - terminal.buffer.ydisp = 0; - registry = new CharacterJoinerRegistry(terminal); + registry = new CharacterJoinerRegistry(bufferService); }); it('has no joiners upon creation', () => { diff --git a/src/renderer/CharacterJoinerRegistry.ts b/src/renderer/CharacterJoinerRegistry.ts index 80fff2b1..d5f19fdd 100644 --- a/src/renderer/CharacterJoinerRegistry.ts +++ b/src/renderer/CharacterJoinerRegistry.ts @@ -3,12 +3,12 @@ * @license MIT */ -import { ITerminal } from '../Types'; import { IBufferLine, ICellData, CharData } from 'common/Types'; import { ICharacterJoinerRegistry, ICharacterJoiner } from './Types'; import { AttributeData } from 'common/buffer/AttributeData'; import { WHITESPACE_CELL_CHAR, Content } from 'common/buffer/Constants'; import { CellData } from 'common/buffer/CellData'; +import { IBufferService } from 'common/services/Services'; export class JoinedCellData extends AttributeData implements ICellData { private _width: number; @@ -61,8 +61,7 @@ export class CharacterJoinerRegistry implements ICharacterJoinerRegistry { private _nextCharacterJoinerId: number = 0; private _workCell: CellData = new CellData(); - constructor(private _terminal: ITerminal) { - } + constructor(private _bufferService: IBufferService) { } public registerCharacterJoiner(handler: (text: string) => [number, number][]): number { const joiner: ICharacterJoiner = { @@ -90,7 +89,7 @@ export class CharacterJoinerRegistry implements ICharacterJoinerRegistry { return []; } - const line = this._terminal.buffer.lines.get(row); + const line = this._bufferService.buffer.lines.get(row); if (line.length === 0) { return []; } @@ -144,7 +143,7 @@ export class CharacterJoinerRegistry implements ICharacterJoinerRegistry { } // Process any trailing ranges. - if (this._terminal.cols - rangeStartColumn > 1) { + if (this._bufferService.cols - rangeStartColumn > 1) { const joinedRanges = this._getJoinedRanges( lineStr, rangeStartStringIndex, @@ -204,7 +203,7 @@ export class CharacterJoinerRegistry implements ICharacterJoinerRegistry { return; } - for (let x = startCol; x < this._terminal.cols; x++) { + for (let x = startCol; x < this._bufferService.cols; x++) { const width = line.getWidth(x); const length = line.getString(x).length || WHITESPACE_CELL_CHAR.length; @@ -252,7 +251,7 @@ export class CharacterJoinerRegistry implements ICharacterJoinerRegistry { // If there is still a range left at the end, it must extend all the way to // the end of the line. if (currentRange) { - currentRange[1] = this._terminal.cols; + currentRange[1] = this._bufferService.cols; } }