diff --git a/src/Buffer.ts b/src/Buffer.ts index 32548eeb..463b2451 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -4,10 +4,10 @@ */ import { CircularList } from './common/CircularList'; -import { CharData, ITerminal, IBuffer, IBufferLine, BufferIndex, IBufferStringIterator, IBufferStringIteratorResult } from './Types'; +import { CharData, ITerminal, IBuffer, IBufferLine, BufferIndex, IBufferStringIterator, IBufferStringIteratorResult, ICellData } from './Types'; import { EventEmitter } from './common/EventEmitter'; import { IMarker } from 'xterm'; -import { BufferLine } from './BufferLine'; +import { BufferLine, CellData } from './BufferLine'; import { DEFAULT_COLOR } from './renderer/atlas/Types'; export const DEFAULT_ATTR = (0 << 18) | (DEFAULT_COLOR << 9) | (256 << 0); @@ -45,6 +45,8 @@ export class Buffer implements IBuffer { public savedX: number; public savedCurAttr: number; public markers: Marker[] = []; + private _nullCell: ICellData = CellData.fromCharData([0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]); + private _whitespaceCell: ICellData = CellData.fromCharData([0, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_WIDTH, WHITESPACE_CELL_CODE]); /** * Create a new Buffer. @@ -59,6 +61,18 @@ export class Buffer implements IBuffer { this.clear(); } + public getNullCell(fg: number = 0, bg: number = 0): ICellData { + this._nullCell.fg = fg; + this._nullCell.bg = bg; + return this._nullCell; + } + + public getWhitespaceCell(fg: number = 0, bg: number = 0): ICellData { + this._whitespaceCell.fg = fg; + this._whitespaceCell.bg = bg; + return this._whitespaceCell; + } + public getBlankLine(attr: number, isWrapped?: boolean): IBufferLine { const fillCharData: CharData = [attr, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]; return new BufferLine(this._terminal.cols, fillCharData, isWrapped); diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 72a86e42..c8f9e7f2 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -519,13 +519,10 @@ 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._cell + this._terminal.buffer.getNullCell(this._terminal.eraseAttr()) ); this._terminal.updateRange(this._terminal.buffer.y); } diff --git a/src/Types.ts b/src/Types.ts index 216139b7..9a4401b6 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -298,6 +298,8 @@ export interface IBuffer { getBlankLine(attr: number, isWrapped?: boolean): IBufferLine; stringIndexToBufferIndex(lineIndex: number, stringIndex: number): number[]; iterator(trimRight: boolean, startIndex?: number, endIndex?: number, startOverscan?: number, endOverscan?: number): IBufferStringIterator; + getNullCell(fg?: number, bg?: number): ICellData; + getWhitespaceCell(fg?: number, bg?: number): ICellData; } export interface IBufferSet extends IEventEmitter { diff --git a/src/ui/TestUtils.test.ts b/src/ui/TestUtils.test.ts index e6e4aaa3..9d525fbf 100644 --- a/src/ui/TestUtils.test.ts +++ b/src/ui/TestUtils.test.ts @@ -4,7 +4,7 @@ */ import { IColorSet, IRenderer, IRenderDimensions, IColorManager } from '../renderer/Types'; -import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, ILinkifier, IMouseHelper, ILinkMatcherOptions, CharacterJoinerHandler, IBufferLine, IBufferStringIterator } from '../Types'; +import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminal, IBuffer, IBufferSet, IBrowser, ICharMeasure, ISelectionManager, ITerminalOptions, ILinkifier, IMouseHelper, ILinkMatcherOptions, CharacterJoinerHandler, IBufferLine, IBufferStringIterator, ICellData } from '../Types'; import { ICircularList, XtermListener } from '../common/Types'; import { Buffer } from '../Buffer'; import * as Browser from '../core/Platform'; @@ -334,6 +334,12 @@ export class MockBuffer implements IBuffer { iterator(trimRight: boolean, startIndex?: number, endIndex?: number): IBufferStringIterator { return Buffer.prototype.iterator.apply(this, arguments); } + getNullCell(fg: number = 0, bg: number = 0): ICellData { + throw new Error('Method not implemented.'); + } + getWhitespaceCell(fg: number = 0, bg: number = 0): ICellData { + throw new Error('Method not implemented.'); + } } export class MockRenderer implements IRenderer {