diff --git a/src/Terminal.ts b/src/Terminal.ts index c5537cc4..e5e3c755 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -1713,6 +1713,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II * @param x The column from which to start erasing to the end of the line. * @param y The line in which to operate. */ + // FIXME: decide whether to remove from Terminal public eraseRight(x: number, y: number): void { const line = this.buffer.lines.get(this.buffer.ybase + y); if (!line) return; @@ -1725,6 +1726,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II * @param x The column from which to start erasing to the start of the line. * @param y The line in which to operate. */ + // FIXME: decide whether to remove from Terminal public eraseLeft(x: number, y: number): void { const line = this.buffer.lines.get(this.buffer.ybase + y); if (!line) return; @@ -1756,6 +1758,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II * Erase all content in the given line * @param y The line to erase all of its contents. */ + // FIXME: decide whether to remove from Terminal public eraseLine(y: number): void { this.eraseRight(0, y); } diff --git a/src/TerminalLine.test.ts b/src/TerminalLine.test.ts index e5a57aa5..72cea26d 100644 --- a/src/TerminalLine.test.ts +++ b/src/TerminalLine.test.ts @@ -50,4 +50,41 @@ describe('TerminalLine', function(): void { chai.expect(ch[CHAR_DATA_WIDTH_INDEX]).equals(NULL_CELL_WIDTH); chai.expect(ch[CHAR_DATA_CODE_INDEX]).equals(NULL_CELL_CODE); }); + it('insertCells', function(): void { + const line = new TerminalLine(); + const data: CharData[] = [ + [1, 'a', 0, 0], + [2, 'b', 0, 0], + [3, 'c', 0, 0] + ]; + for (let i = 0; i < data.length; ++i) line.push(data[i]); + line.insertCells(1, 3, [4, 'd', 0, 0]); + chai.expect(line.toArray()).eql([[1, 'a', 0, 0], [4, 'd', 0, 0], [4, 'd', 0, 0]]); + }); + it('deleteCells', function(): void { + const line = new TerminalLine(); + const data: CharData[] = [ + [1, 'a', 0, 0], + [2, 'b', 0, 0], + [3, 'c', 0, 0], + [4, 'd', 0, 0], + [5, 'e', 0, 0] + ]; + for (let i = 0; i < data.length; ++i) line.push(data[i]); + line.deleteCells(1, 2, [6, 'f', 0, 0]); + chai.expect(line.toArray()).eql([[1, 'a', 0, 0], [4, 'd', 0, 0], [5, 'e', 0, 0], [6, 'f', 0, 0], [6, 'f', 0, 0]]); + }); + it('replaceCells', function(): void { + const line = new TerminalLine(); + const data: CharData[] = [ + [1, 'a', 0, 0], + [2, 'b', 0, 0], + [3, 'c', 0, 0], + [4, 'd', 0, 0], + [5, 'e', 0, 0] + ]; + for (let i = 0; i < data.length; ++i) line.push(data[i]); + line.replaceCells(2, 4, [6, 'f', 0, 0]); + chai.expect(line.toArray()).eql([[1, 'a', 0, 0], [2, 'b', 0, 0], [6, 'f', 0, 0], [6, 'f', 0, 0], [5, 'e', 0, 0]]); + }); }); diff --git a/src/TerminalLine.ts b/src/TerminalLine.ts index f88ca1f4..1fd184d6 100644 --- a/src/TerminalLine.ts +++ b/src/TerminalLine.ts @@ -10,14 +10,15 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer'; * Currently the class is a thin proxy to `CharData[]`. * Once the storages are in place it will proxy access to * typed array based line data. - * TODO: move typical line actions in `InputHandler` and `Terminal` here: - * - create blank line - done - * - insert cells - done - * - remove cells - done - * - maybe Buffer.translateBufferLineToString - * - * next steps towards typed array: - * - replace all external push/pop/splice accesses + * TODO: + * - move Buffer.translateBufferLineToString here? + * - next steps towards typed array: + * - create ITerminalLine interface w'o length methods + * - resize method + * - replace all external push/pop/splice accesses + * - fixed length + * - remove push/pop/splice + * - 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]; @@ -36,21 +37,6 @@ export class TerminalLine { for (let i = 0; i < cols; i++) this.push(ch); // Note: the ctor ch is not cloned } if (isWrapped) this.isWrapped = true; - // for debugging purpose: - // throw Error when something tries to do number index access - // TODO: remove when done with transition - /* - for (let i = 0; i < 100; ++i) { - Object.defineProperty(this, i.toString(), { - get: () => { - throw new Error('get per index access is disabled'); - }, - set: (value: any) => { - throw new Error('set per index access is disabled'); - } - }); - } - */ } get(index: number): CharData { return this._data[index]; @@ -59,17 +45,20 @@ export class TerminalLine { this._data[index] = data; // TODO: unref old, ref new } + // to be removed for typed array pop(): CharData | undefined { // TODO: unref here, change CharData to [typeof Attributes, ...] const data = this._data.pop(); this.length = this._data.length; return data; } + // to be removed for typed array push(data: CharData): void { this._data.push(data); this.length = this._data.length; // TODO: ref here } + // to be removed for typed array splice(start: number, deleteCount: number, ...items: CharData[]): CharData[] { const removed = this._data.splice(start, deleteCount, ...items); this.length = this._data.length;