refactor: serialize-addon, remove equalFg(), equalBg(), equalFlags() api from xterm.d.ts

This commit is contained in:
javacs3
2019-12-18 20:27:39 +08:00
parent b80b5a94f9
commit 84f5f20edb
3 changed files with 25 additions and 25 deletions
@@ -61,6 +61,26 @@ abstract class BaseSerializeHandler {
protected _serializeFinished(): string { return ''; } 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 { class StringSerializeHandler extends BaseSerializeHandler {
private _rowIndex: number = 0; private _rowIndex: number = 0;
private _allRows: string[] = new Array<string>(); private _allRows: string[] = new Array<string>();
@@ -83,9 +103,9 @@ class StringSerializeHandler extends BaseSerializeHandler {
protected _nextCell(cell: IBufferCell, oldCell: IBufferCell, row: number, col: number): void { protected _nextCell(cell: IBufferCell, oldCell: IBufferCell, row: number, col: number): void {
const sgrSeq: number[] = []; const sgrSeq: number[] = [];
const fgChanged = !cell.equalFg(oldCell); const fgChanged = !equalFg(cell, oldCell);
const bgChanged = !cell.equalBg(oldCell); const bgChanged = !equalBg(cell, oldCell);
const flagsChanged = !cell.equalFlags(oldCell); const flagsChanged = !equalFlags(cell, oldCell);
if (fgChanged || bgChanged || flagsChanged) { if (fgChanged || bgChanged || flagsChanged) {
if (cell.isAttributeDefault()) { if (cell.isAttributeDefault()) {
+1 -17
View File
@@ -7,7 +7,7 @@ import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILink
import { ITerminal } from '../Types'; import { ITerminal } from '../Types';
import { IBufferLine } from 'common/Types'; import { IBufferLine } from 'common/Types';
import { IBuffer } from 'common/buffer/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 { CellData } from 'common/buffer/CellData';
import { Terminal as TerminalCore } from '../Terminal'; import { Terminal as TerminalCore } from '../Terminal';
import * as Strings from '../browser/LocalizableStrings'; 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 { class BufferCellApiView implements IBufferCellApi {
constructor(public cell: CellData) {} constructor(public cell: CellData) {}
@@ -266,18 +262,6 @@ class BufferCellApiView implements IBufferCellApi {
public getFgColor(): number { return this.cell.getFgColor(); } public getFgColor(): number { return this.cell.getFgColor(); }
public getBgColor(): number { return this.cell.getBgColor(); } 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 { class ParserApi implements IParser {
+1 -5
View File
@@ -439,7 +439,7 @@ declare module 'xterm' {
* Currently this is only used for a certain type of mouse reports that * Currently this is only used for a certain type of mouse reports that
* happen to be not UTF-8 compatible. * happen to be not UTF-8 compatible.
* The event value is a JS string, pass it to the underlying pty as * 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. * @returns an `IDisposable` to stop listening.
*/ */
onBinary: IEvent<string>; onBinary: IEvent<string>;
@@ -1049,10 +1049,6 @@ declare module 'xterm' {
isAttributeDefault(): boolean; isAttributeDefault(): boolean;
isFgDefault(): boolean; isFgDefault(): boolean;
isBgDefault(): boolean; isBgDefault(): boolean;
equalFg(cell: IBufferCell): boolean;
equalBg(cell: IBufferCell): boolean;
equalFlags(cell: IBufferCell): boolean;
} }
/** /**