From 88a037b3092f4d05862848ba0ee9ba3fbaed9502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Sat, 12 Jan 2019 14:34:29 +0100 Subject: [PATCH] change insertCells to new interface --- src/BufferLine.test.ts | 4 ++-- src/BufferLine.ts | 8 +++----- src/InputHandler.ts | 10 ++++++++-- src/Types.ts | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/BufferLine.test.ts b/src/BufferLine.test.ts index fbf8b051..4ccfe96b 100644 --- a/src/BufferLine.test.ts +++ b/src/BufferLine.test.ts @@ -3,7 +3,7 @@ * @license MIT */ import * as chai from 'chai'; -import { BufferLine } from './BufferLine'; +import { BufferLine, CellData } from './BufferLine'; import { CharData, IBufferLine } from './Types'; import { NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR } from './Buffer'; @@ -41,7 +41,7 @@ describe('BufferLine', function(): void { line.set(0, [1, 'a', 0, 'a'.charCodeAt(0)]); line.set(1, [2, 'b', 0, 'b'.charCodeAt(0)]); line.set(2, [3, 'c', 0, 'c'.charCodeAt(0)]); - line.insertCells(1, 3, [4, 'd', 0, 'd'.charCodeAt(0)]); + line.insertCells(1, 3, CellData.fromCharData([4, 'd', 0, 'd'.charCodeAt(0)])); chai.expect(line.toArray()).eql([ [1, 'a', 0, 'a'.charCodeAt(0)], [4, 'd', 0, 'd'.charCodeAt(0)], diff --git a/src/BufferLine.ts b/src/BufferLine.ts index b3a94672..64cb1e19 100644 --- a/src/BufferLine.ts +++ b/src/BufferLine.ts @@ -279,20 +279,18 @@ export class BufferLine implements IBufferLine { } } - public insertCells(pos: number, n: number, fillCharData: CharData): void { + public insertCells(pos: number, n: number, fillCellData: ICellData): void { pos %= this.length; if (n < this.length - pos) { for (let i = this.length - pos - n - 1; i >= 0; --i) { this.setCell(pos + n + i, this.loadCell(pos + i, this._cell)); } - this._cell.setFromCharData(fillCharData); for (let i = 0; i < n; ++i) { - this.setCell(pos + i, this._cell); + this.setCell(pos + i, fillCellData); } } else { - this._cell.setFromCharData(fillCharData); for (let i = pos; i < this.length; ++i) { - this.setCell(i, this._cell); + this.setCell(i, fillCellData); } } } diff --git a/src/InputHandler.ts b/src/InputHandler.ts index ad3713e9..72a86e42 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -396,7 +396,10 @@ export class InputHandler extends Disposable implements IInputHandler { // insert mode: move characters to right if (insertMode) { // right shift cells according to the width - bufferRow.insertCells(buffer.x, chWidth, [curAttr, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]); + this._cell.fg = curAttr; + this._cell.bg = 0; + this._cell.content = 0; + bufferRow.insertCells(buffer.x, chWidth, this._cell); // test last cell - since the last cell has only room for // a halfwidth char any fullwidth shifted there is lost // and will be set to eraseChar @@ -516,10 +519,13 @@ export class InputHandler extends Disposable implements IInputHandler { * Insert Ps (Blank) Character(s) (default = 1) (ICH). */ public insertChars(params: number[]): void { + this._cell.content = 0; + this._cell.fg = this._terminal.eraseAttr(); + this._cell.bg = 0; this._terminal.buffer.lines.get(this._terminal.buffer.y + this._terminal.buffer.ybase).insertCells( this._terminal.buffer.x, params[0] || 1, - [this._terminal.eraseAttr(), NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE] + this._cell ); this._terminal.updateRange(this._terminal.buffer.y); } diff --git a/src/Types.ts b/src/Types.ts index c1a7788a..216139b7 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -536,7 +536,7 @@ export interface IBufferLine { setCell(index: number, cell: ICellData): void; setDataFromCodePoint(index: number, codePoint: number, width: number, fg: number, bg: number): void; addCharToCell(index: number, codePoint: number): void; - insertCells(pos: number, n: number, ch: CharData): void; + insertCells(pos: number, n: number, ch: ICellData): void; deleteCells(pos: number, n: number, fill: CharData): void; replaceCells(start: number, end: number, fill: CharData): void; resize(cols: number, fill: CharData, shrink?: boolean): void;