From a2480bae51b86a368cea3784b4bcb07e9e139caa Mon Sep 17 00:00:00 2001 From: Mmis1000 Date: Sat, 23 Jan 2021 11:57:08 +0800 Subject: [PATCH] Remove dummy buffer cell in favor of just remember the location --- .../xterm-addon-serialize/src/MyBufferCell.ts | 96 ------------------- .../src/SerializeAddon.ts | 18 +++- 2 files changed, 14 insertions(+), 100 deletions(-) delete mode 100644 addons/xterm-addon-serialize/src/MyBufferCell.ts diff --git a/addons/xterm-addon-serialize/src/MyBufferCell.ts b/addons/xterm-addon-serialize/src/MyBufferCell.ts deleted file mode 100644 index d635a424..00000000 --- a/addons/xterm-addon-serialize/src/MyBufferCell.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { IBufferCell } from 'xterm'; - -/** - * This is a dummy buffer cell to hold data from real buffer cell - */ -export class MyBufferCell implements IBufferCell { - constructor(private _cell: IBufferCell) {} - private _width: number = this._cell.getWidth(); - private _chars: string = this._cell.getChars(); - private _code: number = this._cell.getCode(); - private _fgColorMode: number = this._cell.getFgColorMode(); - private _bgColorMode: number = this._cell.getBgColorMode(); - private _fgColor: number = this._cell.getFgColor(); - private _bgColor: number = this._cell.getBgColor(); - private _bold: number = this._cell.isBold(); - private _italic: number = this._cell.isItalic(); - private _dim: number = this._cell.isDim(); - private _underline: number = this._cell.isUnderline(); - private _blink: number = this._cell.isBlink(); - private _inverse: number = this._cell.isInverse(); - private _invisible: number = this._cell.isInvisible(); - private _fgRGB: boolean = this._cell.isFgRGB(); - private _bgRGB: boolean = this._cell.isBgRGB(); - private _fgPalette: boolean = this._cell.isFgPalette(); - private _bgPallette: boolean = this._cell.isBgPalette(); - private _fgDefault: boolean = this._cell.isFgDefault(); - private _bgDefault: boolean = this._cell.isBgDefault(); - private _attributeDefault: boolean = this._cell.isAttributeDefault(); - public getWidth(): number { - return this._width; - } - public getChars(): string { - return this._chars; - } - public getCode(): number { - return this._code; - } - public getFgColorMode(): number { - return this._fgColorMode; - } - public getBgColorMode(): number { - return this._bgColorMode; - } - public getFgColor(): number { - return this._fgColor; - } - public getBgColor(): number { - return this._bgColor; - } - public isBold(): number { - return this._bold; - } - public isItalic(): number { - return this._italic; - } - public isDim(): number { - return this._dim; - } - public isUnderline(): number { - return this._underline; - } - public isBlink(): number { - return this._blink; - } - public isInverse(): number { - return this._inverse; - } - public isInvisible(): number { - return this._invisible; - } - public isFgRGB(): boolean { - return this._fgRGB; - } - public isBgRGB(): boolean { - return this._bgRGB; - } - public isFgPalette(): boolean { - return this._fgPalette; - } - public isBgPalette(): boolean { - return this._bgPallette; - } - public isFgDefault(): boolean { - return this._fgDefault; - } - public isBgDefault(): boolean { - return this._bgDefault; - } - public isAttributeDefault(): boolean { - return this._attributeDefault; - } - - public static from(cell: IBufferCell): MyBufferCell { - return new MyBufferCell(cell); - } -} diff --git a/addons/xterm-addon-serialize/src/SerializeAddon.ts b/addons/xterm-addon-serialize/src/SerializeAddon.ts index 9641dc20..60fe9624 100644 --- a/addons/xterm-addon-serialize/src/SerializeAddon.ts +++ b/addons/xterm-addon-serialize/src/SerializeAddon.ts @@ -6,7 +6,6 @@ */ import { Terminal, ITerminalAddon, IBuffer, IBufferCell } from 'xterm'; -import { MyBufferCell } from './MyBufferCell'; function constrain(value: number, low: number, high: number): number { return Math.max(low, Math.min(value, high)); @@ -86,8 +85,14 @@ class StringSerializeHandler extends BaseSerializeHandler { // so wee need to record it when required. private _cursorStyle: IBufferCell = this._buffer1.getNullCell(); + // where exact the cursor styles comes from + // because we can't copy the cell directly + // so we remember where the content comes from instead + private _cursorStyleRow: number = 0; + private _cursorStyleCol: number = 0; + // this is a null cell for reference for checking whether background is empty or not - private _backgroundCell: MyBufferCell = MyBufferCell.from(this._cursorStyle); + private _backgroundCell: IBufferCell = this._buffer1.getNullCell(); private _firstRow: number = 0; private _lastCursorRow: number = 0; @@ -122,7 +127,7 @@ class StringSerializeHandler extends BaseSerializeHandler { if (!isLastRow) { // Enable BCE if (row - this._firstRow >= this._terminal.rows) { - this._backgroundCell = MyBufferCell.from(this._cursorStyle); + this._buffer1.getLine(this._cursorStyleRow)?.getCell(this._cursorStyleCol, this._backgroundCell); } // Fetch current line @@ -283,7 +288,12 @@ class StringSerializeHandler extends BaseSerializeHandler { this._currentRow += `\x1b[${sgrSeq.join(';')}m`; // update the last cursor style - this._buffer1.getLine(row)?.getCell(col, this._cursorStyle); + const line = this._buffer1.getLine(row); + if (line !== undefined) { + line.getCell(col, this._cursorStyle); + this._cursorStyleRow = row; + this._cursorStyleCol = col; + } } /**