From 228ec7b818dc81bca10dce2e7aacfa5e4e078059 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 9 May 2019 22:15:32 -0700 Subject: [PATCH] Move BufferLine into core --- src/Buffer.test.ts | 2 +- src/Buffer.ts | 2 +- src/BufferLine.test.ts | 3 +-- src/BufferReflow.test.ts | 2 +- src/BufferReflow.ts | 2 +- src/CharWidth.test.ts | 2 +- src/InputHandler.test.ts | 2 +- src/InputHandler.ts | 2 +- src/Linkifier.test.ts | 2 +- src/SelectionManager.test.ts | 2 +- src/SelectionManager.ts | 2 +- src/Terminal.integration.ts | 2 +- src/Terminal.test.ts | 2 +- src/Terminal.ts | 2 +- src/TestUtils.test.ts | 2 +- src/WindowsMode.ts | 2 +- src/{ => core/buffer}/BufferLine.ts | 20 +++++++++---------- src/renderer/BaseRenderLayer.ts | 2 +- src/renderer/CharacterJoinerRegistry.test.ts | 2 +- src/renderer/CharacterJoinerRegistry.ts | 2 +- src/renderer/CursorRenderLayer.ts | 2 +- src/renderer/TextRenderLayer.ts | 2 +- .../dom/DomRendererRowFactory.test.ts | 2 +- src/renderer/dom/DomRendererRowFactory.ts | 2 +- 24 files changed, 32 insertions(+), 35 deletions(-) rename src/{ => core/buffer}/BufferLine.ts (97%) diff --git a/src/Buffer.test.ts b/src/Buffer.test.ts index 618a979548..087d0ae528 100644 --- a/src/Buffer.test.ts +++ b/src/Buffer.test.ts @@ -8,7 +8,7 @@ import { ITerminal } from './Types'; import { Buffer } from './Buffer'; import { CircularList } from './common/CircularList'; import { MockTerminal, TestTerminal } from './TestUtils.test'; -import { BufferLine, CellData, DEFAULT_ATTR_DATA } from './BufferLine'; +import { BufferLine, CellData, DEFAULT_ATTR_DATA } from './core/buffer/BufferLine'; const INIT_COLS = 80; const INIT_ROWS = 24; diff --git a/src/Buffer.ts b/src/Buffer.ts index 7e986a6c02..14bf53aaff 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -7,7 +7,7 @@ import { CircularList, IInsertEvent } from './common/CircularList'; import { ITerminal, IBuffer, BufferIndex, IBufferStringIterator, IBufferStringIteratorResult } from './Types'; import { IBufferLine, ICellData, IAttributeData } from './core/Types'; import { IMarker } from 'xterm'; -import { BufferLine, CellData, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_WIDTH, WHITESPACE_CELL_CODE, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX, DEFAULT_ATTR_DATA } from './BufferLine'; +import { BufferLine, CellData, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_WIDTH, WHITESPACE_CELL_CODE, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX, DEFAULT_ATTR_DATA } from './core/buffer/BufferLine'; import { reflowLargerApplyNewLayout, reflowLargerCreateNewLayout, reflowLargerGetLinesToRemove, reflowSmallerGetNewLineLengths, getWrappedLineTrimmedLength } from './BufferReflow'; import { EventEmitter2, IEvent } from './common/EventEmitter2'; import { Disposable } from '../lib/common/Lifecycle'; diff --git a/src/BufferLine.test.ts b/src/BufferLine.test.ts index b9e40491dc..87a4e63167 100644 --- a/src/BufferLine.test.ts +++ b/src/BufferLine.test.ts @@ -3,10 +3,9 @@ * @license MIT */ import * as chai from 'chai'; -import { BufferLine, CellData, Content, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR } from './BufferLine'; +import { BufferLine, CellData, Content, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR } from './core/buffer/BufferLine'; import { CharData, IBufferLine } from './core/Types'; - class TestBufferLine extends BufferLine { public get combined(): {[index: number]: string} { return this._combined; diff --git a/src/BufferReflow.test.ts b/src/BufferReflow.test.ts index 9a2f3906ef..91454e2aa3 100644 --- a/src/BufferReflow.test.ts +++ b/src/BufferReflow.test.ts @@ -3,7 +3,7 @@ * @license MIT */ import { assert } from 'chai'; -import { BufferLine, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE } from './BufferLine'; +import { BufferLine, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE } from './core/buffer/BufferLine'; import { reflowSmallerGetNewLineLengths } from './BufferReflow'; describe('BufferReflow', () => { diff --git a/src/BufferReflow.ts b/src/BufferReflow.ts index 7c53de7a48..c106896714 100644 --- a/src/BufferReflow.ts +++ b/src/BufferReflow.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { BufferLine } from './BufferLine'; +import { BufferLine } from './core/buffer/BufferLine'; import { CircularList } from './common/CircularList'; import { IBufferLine, ICellData } from './core/Types'; diff --git a/src/CharWidth.test.ts b/src/CharWidth.test.ts index 0821d8645f..17822fa28a 100644 --- a/src/CharWidth.test.ts +++ b/src/CharWidth.test.ts @@ -7,7 +7,7 @@ import { TestTerminal } from './TestUtils.test'; import { assert } from 'chai'; import { getStringCellWidth, wcwidth } from './CharWidth'; import { IBuffer } from './Types'; -import { CellData, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from './BufferLine'; +import { CellData, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CHAR_INDEX } from './core/buffer/BufferLine'; describe('getStringCellWidth', function(): void { diff --git a/src/InputHandler.test.ts b/src/InputHandler.test.ts index c02867799b..f2e8d93e92 100644 --- a/src/InputHandler.test.ts +++ b/src/InputHandler.test.ts @@ -8,7 +8,7 @@ import { InputHandler } from './InputHandler'; import { MockInputHandlingTerminal, TestTerminal } from './TestUtils.test'; import { Terminal } from './Terminal'; import { IBufferLine } from './core/Types'; -import { CellData, Attributes, AttributeData, DEFAULT_ATTR_DATA } from './BufferLine'; +import { CellData, Attributes, AttributeData, DEFAULT_ATTR_DATA } from './core/buffer/BufferLine'; describe('InputHandler', () => { describe('save and restore cursor', () => { diff --git a/src/InputHandler.ts b/src/InputHandler.ts index ebdc9d0d14..b5b98dd964 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -13,7 +13,7 @@ import { IDisposable } from 'xterm'; import { Disposable } from './common/Lifecycle'; import { concat } from './common/TypedArrayUtils'; import { StringToUtf32, stringFromCodePoint, utf32ToString } from './core/input/TextDecoder'; -import { CellData, Attributes, FgFlags, BgFlags, AttributeData, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR_DATA } from './BufferLine'; +import { CellData, Attributes, FgFlags, BgFlags, AttributeData, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR_DATA } from './core/buffer/BufferLine'; import { EventEmitter2, IEvent } from './common/EventEmitter2'; /** diff --git a/src/Linkifier.test.ts b/src/Linkifier.test.ts index d22244c9f4..6a2f0ee927 100644 --- a/src/Linkifier.test.ts +++ b/src/Linkifier.test.ts @@ -9,7 +9,7 @@ import { IBufferLine } from './core/Types'; import { Linkifier } from './Linkifier'; import { MockBuffer, MockTerminal, TestTerminal } from './TestUtils.test'; import { CircularList } from './common/CircularList'; -import { BufferLine, CellData } from './BufferLine'; +import { BufferLine, CellData } from './core/buffer/BufferLine'; class TestLinkifier extends Linkifier { constructor(terminal: ITerminal) { diff --git a/src/SelectionManager.test.ts b/src/SelectionManager.test.ts index 07bbe8be10..24ba01005a 100644 --- a/src/SelectionManager.test.ts +++ b/src/SelectionManager.test.ts @@ -11,7 +11,7 @@ import { BufferSet } from './BufferSet'; import { ITerminal, IBuffer } from './Types'; import { IBufferLine } from './core/Types'; import { MockTerminal } from './TestUtils.test'; -import { BufferLine, CellData } from './BufferLine'; +import { BufferLine, CellData } from './core/buffer/BufferLine'; class TestMockTerminal extends MockTerminal { emit(event: string, data: any): void {} diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 2d65134802..dabcc9a4d9 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -10,7 +10,7 @@ import * as Browser from './common/Platform'; import { CharMeasure } from './CharMeasure'; import { SelectionModel } from './SelectionModel'; import { AltClickHandler } from './handlers/AltClickHandler'; -import { CellData } from './BufferLine'; +import { CellData } from './core/buffer/BufferLine'; import { IDisposable } from 'xterm'; import { EventEmitter2, IEvent } from './common/EventEmitter2'; diff --git a/src/Terminal.integration.ts b/src/Terminal.integration.ts index b03627dfc7..5e12d2a308 100644 --- a/src/Terminal.integration.ts +++ b/src/Terminal.integration.ts @@ -14,7 +14,7 @@ import * as pty from 'node-pty'; import { assert } from 'chai'; import { Terminal } from './Terminal'; import { IViewport } from './Types'; -import { CellData, WHITESPACE_CELL_CHAR } from './BufferLine'; +import { CellData, WHITESPACE_CELL_CHAR } from './core/buffer/BufferLine'; class TestTerminal extends Terminal { innerWrite(): void { this._innerWrite(); } diff --git a/src/Terminal.test.ts b/src/Terminal.test.ts index 06a02d68d2..9b5fa9c8b1 100644 --- a/src/Terminal.test.ts +++ b/src/Terminal.test.ts @@ -6,7 +6,7 @@ import { assert, expect } from 'chai'; import { Terminal } from './Terminal'; import { MockViewport, MockCompositionHelper, MockRenderer } from './TestUtils.test'; -import { CellData, DEFAULT_ATTR_DATA } from './BufferLine'; +import { CellData, DEFAULT_ATTR_DATA } from './core/buffer/BufferLine'; const INIT_COLS = 80; const INIT_ROWS = 24; diff --git a/src/Terminal.ts b/src/Terminal.ts index 0ff21b88ae..6da60458ec 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -51,7 +51,7 @@ import { evaluateKeyboardEvent } from './core/input/Keyboard'; import { KeyboardResultType, ICharset, IBufferLine, IAttributeData } from './core/Types'; import { clone } from './common/Clone'; import { EventEmitter2, IEvent } from './common/EventEmitter2'; -import { Attributes, DEFAULT_ATTR_DATA } from './BufferLine'; +import { Attributes, DEFAULT_ATTR_DATA } from './core/buffer/BufferLine'; import { applyWindowsMode } from './WindowsMode'; // Let it work inside Node.js for automated testing purposes. diff --git a/src/TestUtils.test.ts b/src/TestUtils.test.ts index 8170681d81..1d5008c8b3 100644 --- a/src/TestUtils.test.ts +++ b/src/TestUtils.test.ts @@ -11,7 +11,7 @@ import { Buffer } from './Buffer'; import * as Browser from './common/Platform'; import { ITheme, IDisposable, IMarker, IEvent } from 'xterm'; import { Terminal } from './Terminal'; -import { AttributeData } from './BufferLine'; +import { AttributeData } from './core/buffer/BufferLine'; export class TestTerminal extends Terminal { writeSync(data: string): void { diff --git a/src/WindowsMode.ts b/src/WindowsMode.ts index 1e58c50ce4..d7b4bcaec8 100644 --- a/src/WindowsMode.ts +++ b/src/WindowsMode.ts @@ -5,7 +5,7 @@ import { IDisposable } from 'xterm'; import { ITerminal } from './Types'; -import { CHAR_DATA_CODE_INDEX, NULL_CELL_CODE, WHITESPACE_CELL_CODE } from './BufferLine'; +import { CHAR_DATA_CODE_INDEX, NULL_CELL_CODE, WHITESPACE_CELL_CODE } from './core/buffer/BufferLine'; export function applyWindowsMode(terminal: ITerminal): IDisposable { // Winpty does not support wraparound mode which means that lines will never diff --git a/src/BufferLine.ts b/src/core/buffer/BufferLine.ts similarity index 97% rename from src/BufferLine.ts rename to src/core/buffer/BufferLine.ts index 39b6116d23..154cc5984c 100644 --- a/src/BufferLine.ts +++ b/src/core/buffer/BufferLine.ts @@ -2,9 +2,9 @@ * Copyright (c) 2018 The xterm.js authors. All rights reserved. * @license MIT */ -import { CharData, IBufferLine, ICellData, IColorRGB, IAttributeData } from './core/Types'; -import { stringFromCodePoint } from './core/input/TextDecoder'; -import { DEFAULT_COLOR } from './common/Types'; +import { CharData, IBufferLine, ICellData, IColorRGB, IAttributeData } from '../Types'; +import { stringFromCodePoint } from '../input/TextDecoder'; +import { DEFAULT_COLOR } from '../../common/Types'; export const DEFAULT_ATTR = (0 << 18) | (DEFAULT_COLOR << 9) | (256 << 0); @@ -325,17 +325,15 @@ export class CellData extends AttributeData implements ICellData { * memory allocs / GC pressure can be greatly reduced by reusing the CellData object. */ export class BufferLine implements IBufferLine { - protected _data: Uint32Array | null = null; + protected _data: Uint32Array; protected _combined: {[index: number]: string} = {}; public length: number; constructor(cols: number, fillCellData?: ICellData, public isWrapped: boolean = false) { - if (cols) { - this._data = new Uint32Array(cols * CELL_SIZE); - const cell = fillCellData || CellData.fromCharData([0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]); - for (let i = 0; i < cols; ++i) { - this.setCell(i, cell); - } + this._data = new Uint32Array(cols * CELL_SIZE); + const cell = fillCellData || CellData.fromCharData([0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]); + for (let i = 0; i < cols; ++i) { + this.setCell(i, cell); } this.length = cols; } @@ -573,7 +571,7 @@ export class BufferLine implements IBufferLine { } } } else { - this._data = null; + this._data = new Uint32Array(0); this._combined = {}; } } diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index 63846155be..ce50a65115 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -10,7 +10,7 @@ import { DEFAULT_COLOR } from '../common/Types'; import { DIM_OPACITY, INVERTED_DEFAULT_COLOR, IGlyphIdentifier } from './atlas/Types'; import BaseCharAtlas from './atlas/BaseCharAtlas'; import { acquireCharAtlas } from './atlas/CharAtlasCache'; -import { CellData, AttributeData, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_CODE } from '../BufferLine'; +import { CellData, AttributeData, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_CODE } from '../core/buffer/BufferLine'; import { JoinedCellData } from './CharacterJoinerRegistry'; export abstract class BaseRenderLayer implements IRenderLayer { diff --git a/src/renderer/CharacterJoinerRegistry.test.ts b/src/renderer/CharacterJoinerRegistry.test.ts index 590d6a5f5d..948985a46f 100644 --- a/src/renderer/CharacterJoinerRegistry.test.ts +++ b/src/renderer/CharacterJoinerRegistry.test.ts @@ -10,7 +10,7 @@ import { CircularList } from '../common/CircularList'; import { ICharacterJoinerRegistry } from './Types'; import { CharacterJoinerRegistry } from './CharacterJoinerRegistry'; -import { BufferLine, CellData } from '../BufferLine'; +import { BufferLine, CellData } from '../core/buffer/BufferLine'; import { IBufferLine } from '../core/Types'; describe('CharacterJoinerRegistry', () => { diff --git a/src/renderer/CharacterJoinerRegistry.ts b/src/renderer/CharacterJoinerRegistry.ts index 33cd893609..3302c31216 100644 --- a/src/renderer/CharacterJoinerRegistry.ts +++ b/src/renderer/CharacterJoinerRegistry.ts @@ -6,7 +6,7 @@ import { ITerminal } from '../Types'; import { IBufferLine, ICellData, CharData } from '../core/Types'; import { ICharacterJoinerRegistry, ICharacterJoiner } from './Types'; -import { CellData, Content, AttributeData, WHITESPACE_CELL_CHAR } from '../BufferLine'; +import { CellData, Content, AttributeData, WHITESPACE_CELL_CHAR } from '../core/buffer/BufferLine'; export class JoinedCellData extends AttributeData implements ICellData { private _width: number; diff --git a/src/renderer/CursorRenderLayer.ts b/src/renderer/CursorRenderLayer.ts index 72aaa4471a..3e8af02de6 100644 --- a/src/renderer/CursorRenderLayer.ts +++ b/src/renderer/CursorRenderLayer.ts @@ -7,7 +7,7 @@ import { IColorSet, IRenderDimensions } from './Types'; import { BaseRenderLayer } from './BaseRenderLayer'; import { ITerminal } from '../Types'; import { ICellData } from '../core/Types'; -import { CellData } from '../BufferLine'; +import { CellData } from '../core/buffer/BufferLine'; interface ICursorState { x: number; diff --git a/src/renderer/TextRenderLayer.ts b/src/renderer/TextRenderLayer.ts index 90c7e26773..8be5665c43 100644 --- a/src/renderer/TextRenderLayer.ts +++ b/src/renderer/TextRenderLayer.ts @@ -8,7 +8,7 @@ import { ITerminal } from '../Types'; import { CharData, ICellData } from '../core/Types'; import { GridCache } from './GridCache'; import { BaseRenderLayer } from './BaseRenderLayer'; -import { CellData, AttributeData, Content, NULL_CELL_CODE } from '../BufferLine'; +import { CellData, AttributeData, Content, NULL_CELL_CODE } from '../core/buffer/BufferLine'; import { JoinedCellData } from './CharacterJoinerRegistry'; /** diff --git a/src/renderer/dom/DomRendererRowFactory.test.ts b/src/renderer/dom/DomRendererRowFactory.test.ts index f009407d46..b253059524 100644 --- a/src/renderer/dom/DomRendererRowFactory.test.ts +++ b/src/renderer/dom/DomRendererRowFactory.test.ts @@ -6,7 +6,7 @@ import jsdom = require('jsdom'); import { assert } from 'chai'; import { DomRendererRowFactory } from './DomRendererRowFactory'; -import { BufferLine, CellData, FgFlags, BgFlags, Attributes, NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR, DEFAULT_ATTR, DEFAULT_ATTR_DATA } from '../../BufferLine'; +import { BufferLine, CellData, FgFlags, BgFlags, Attributes, NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR, DEFAULT_ATTR, DEFAULT_ATTR_DATA } from '../../core/buffer/BufferLine'; import { ITerminalOptions } from '../../Types'; import { IBufferLine } from '../../core/Types'; diff --git a/src/renderer/dom/DomRendererRowFactory.ts b/src/renderer/dom/DomRendererRowFactory.ts index 481d096ef1..85ef586e28 100644 --- a/src/renderer/dom/DomRendererRowFactory.ts +++ b/src/renderer/dom/DomRendererRowFactory.ts @@ -6,7 +6,7 @@ import { ITerminalOptions } from '../../Types'; import { IBufferLine } from '../../core/Types'; import { INVERTED_DEFAULT_COLOR } from '../atlas/Types'; -import { CellData, AttributeData, NULL_CELL_CODE, WHITESPACE_CELL_CHAR } from '../../BufferLine'; +import { CellData, AttributeData, NULL_CELL_CODE, WHITESPACE_CELL_CHAR } from '../../core/buffer/BufferLine'; export const BOLD_CLASS = 'xterm-bold'; export const DIM_CLASS = 'xterm-dim';