From 84f5f20edbe5d3cc45035dc6cb4dc03a03abd111 Mon Sep 17 00:00:00 2001 From: javacs3 Date: Wed, 18 Dec 2019 16:09:57 +0800 Subject: [PATCH] refactor: serialize-addon, remove equalFg(), equalBg(), equalFlags() api from xterm.d.ts --- .../src/SerializeAddon.ts | 26 ++++++++++++++++--- src/public/Terminal.ts | 18 +------------ typings/xterm.d.ts | 6 +---- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/addons/xterm-addon-serialize/src/SerializeAddon.ts b/addons/xterm-addon-serialize/src/SerializeAddon.ts index 468b9655..160f6459 100644 --- a/addons/xterm-addon-serialize/src/SerializeAddon.ts +++ b/addons/xterm-addon-serialize/src/SerializeAddon.ts @@ -61,6 +61,26 @@ abstract class BaseSerializeHandler { protected _serializeFinished(): string { return ''; } } +function equalFg(cell1: IBufferCell, cell2: IBufferCell): boolean { + return cell1.getFgColorMode() === cell2.getFgColorMode() + && cell1.getFgColor() === cell2.getFgColor(); +} + +function equalBg(cell1: IBufferCell, cell2: IBufferCell): boolean { + return cell1.getBgColorMode() === cell2.getBgColorMode() + && cell1.getBgColor() === cell2.getBgColor(); +} + +function equalFlags(cell1: IBufferCell, cell2: IBufferCell): boolean { + return cell1.isInverse() === cell2.isInverse() + && cell1.isBold() === cell2.isBold() + && cell1.isUnderline() === cell2.isUnderline() + && cell1.isBlink() === cell2.isBlink() + && cell1.isInvisible() === cell2.isInvisible() + && cell1.isItalic() === cell2.isItalic() + && cell1.isDim() === cell2.isDim(); +} + class StringSerializeHandler extends BaseSerializeHandler { private _rowIndex: number = 0; private _allRows: string[] = new Array(); @@ -83,9 +103,9 @@ class StringSerializeHandler extends BaseSerializeHandler { protected _nextCell(cell: IBufferCell, oldCell: IBufferCell, row: number, col: number): void { const sgrSeq: number[] = []; - const fgChanged = !cell.equalFg(oldCell); - const bgChanged = !cell.equalBg(oldCell); - const flagsChanged = !cell.equalFlags(oldCell); + const fgChanged = !equalFg(cell, oldCell); + const bgChanged = !equalBg(cell, oldCell); + const flagsChanged = !equalFlags(cell, oldCell); if (fgChanged || bgChanged || flagsChanged) { if (cell.isAttributeDefault()) { diff --git a/src/public/Terminal.ts b/src/public/Terminal.ts index 22776d0a..5854cef6 100644 --- a/src/public/Terminal.ts +++ b/src/public/Terminal.ts @@ -7,7 +7,7 @@ import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILink import { ITerminal } from '../Types'; import { IBufferLine } from 'common/Types'; import { IBuffer } from 'common/buffer/Types'; -import { Attributes, FgFlags, BgFlags } from 'common/buffer/Constants'; +import { Attributes } from 'common/buffer/Constants'; import { CellData } from 'common/buffer/CellData'; import { Terminal as TerminalCore } from '../Terminal'; import * as Strings from '../browser/LocalizableStrings'; @@ -227,10 +227,6 @@ class BufferLineApiView implements IBufferLineApi { } } -const FG_FLAG_MASK = FgFlags.BOLD | FgFlags.BLINK | FgFlags.INVERSE | FgFlags.INVISIBLE | FgFlags.UNDERLINE; -const BG_FLAG_MASK = BgFlags.DIM | BgFlags.ITALIC; -const COLOR_MASK = Attributes.CM_MASK | Attributes.RGB_MASK; - class BufferCellApiView implements IBufferCellApi { constructor(public cell: CellData) {} @@ -266,18 +262,6 @@ class BufferCellApiView implements IBufferCellApi { public getFgColor(): number { return this.cell.getFgColor(); } public getBgColor(): number { return this.cell.getBgColor(); } - - - public equalFlags(other: BufferCellApiView): boolean { - return (this.cell.fg & FG_FLAG_MASK) === (other.cell.fg & FG_FLAG_MASK) - && (this.cell.bg & BG_FLAG_MASK) === (other.cell.bg & BG_FLAG_MASK); - } - public equalFg(other: BufferCellApiView): boolean { - return (this.cell.fg & COLOR_MASK) === (other.cell.fg & COLOR_MASK); - } - public equalBg(other: BufferCellApiView): boolean { - return (this.cell.bg & COLOR_MASK) === (other.cell.bg & COLOR_MASK); - } } class ParserApi implements IParser { diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 6bf2aebf..243266d0 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -439,7 +439,7 @@ declare module 'xterm' { * Currently this is only used for a certain type of mouse reports that * happen to be not UTF-8 compatible. * The event value is a JS string, pass it to the underlying pty as - * binary data, e.g. `pty.write(Buffer.from(data, 'binary'))`. + * binary data, e.g. `pty.write(Buffer.from(data, 'binary'))`. * @returns an `IDisposable` to stop listening. */ onBinary: IEvent; @@ -1049,10 +1049,6 @@ declare module 'xterm' { isAttributeDefault(): boolean; isFgDefault(): boolean; isBgDefault(): boolean; - - equalFg(cell: IBufferCell): boolean; - equalBg(cell: IBufferCell): boolean; - equalFlags(cell: IBufferCell): boolean; } /**