From 381e6c174057128597d3a14ca435354bf8624807 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 30 Aug 2018 07:57:03 -0700 Subject: [PATCH] Move defaultCell to an exported member --- src/TerminalLine.test.ts | 6 +++--- src/TerminalLine.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/TerminalLine.test.ts b/src/TerminalLine.test.ts index 72cea26d..f0fd1498 100644 --- a/src/TerminalLine.test.ts +++ b/src/TerminalLine.test.ts @@ -3,7 +3,7 @@ * @license MIT */ import * as chai from 'chai'; -import { TerminalLine } from './TerminalLine'; +import { TerminalLine, defaultCell } from './TerminalLine'; import { CharData } from './Types'; import { NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, CHAR_DATA_ATTR_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_CODE_INDEX } from './Buffer'; @@ -15,11 +15,11 @@ describe('TerminalLine', function(): void { chai.expect(line.isWrapped).equals(false); line = new TerminalLine(10); chai.expect(line.length).equals(10); - chai.expect(line.pop()).eql(TerminalLine.defaultCell); + chai.expect(line.pop()).eql(defaultCell); chai.expect(line.isWrapped).equals(false); line = new TerminalLine(10, null, true); chai.expect(line.length).equals(10); - chai.expect(line.pop()).eql(TerminalLine.defaultCell); + chai.expect(line.pop()).eql(defaultCell); chai.expect(line.isWrapped).equals(true); line = new TerminalLine(10, [123, 'a', 456, 789], true); chai.expect(line.length).equals(10); diff --git a/src/TerminalLine.ts b/src/TerminalLine.ts index 77f3962e..a053bab8 100644 --- a/src/TerminalLine.ts +++ b/src/TerminalLine.ts @@ -5,6 +5,8 @@ import { CharData } from './Types'; import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer'; +export const defaultCell: CharData = [0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]; + /** * Class representing a terminal line. * Currently the class is a thin proxy to `CharData[]`. @@ -21,11 +23,11 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer'; * - implement typed array alternative once string is removed from CharData */ export class TerminalLine { - static defaultCell: CharData = [0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]; - static blankLine(cols: number, attr: number, isWrapped?: boolean): TerminalLine { + public static blankLine(cols: number, attr: number, isWrapped?: boolean): TerminalLine { const ch: CharData = [attr, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]; return new TerminalLine(cols, ch, isWrapped); } + private _data: CharData[]; public isWrapped = false; public length: number; @@ -35,7 +37,7 @@ export class TerminalLine { this.length = this._data.length; if (cols) { if (!ch) { - ch = TerminalLine.defaultCell; + ch = defaultCell; } for (let i = 0; i < cols; i++) { this.push(ch); // Note: the ctor ch is not cloned @@ -82,6 +84,7 @@ export class TerminalLine { public release(): void { // TODO: unref here } + public toArray(): CharData[] { return this._data; }