From 56f4c3d6aefc29370ec0c71593744eb48046dfda Mon Sep 17 00:00:00 2001 From: javacs3 Date: Thu, 9 Jan 2020 21:15:30 +0800 Subject: [PATCH] remove BufferCellApiView --- addons/xterm-addon-search/src/SearchAddon.ts | 4 +- .../src/SerializeAddon.api.ts | 16 +++---- .../src/SerializeAddon.ts | 16 ++++--- addons/xterm-addon-webgl/src/GlyphRenderer.ts | 2 +- src/common/Types.d.ts | 1 + src/common/buffer/AttributeData.ts | 1 + src/common/buffer/Constants.ts | 14 +----- src/public/Terminal.ts | 48 ++----------------- typings/xterm.d.ts | 18 ------- 9 files changed, 30 insertions(+), 90 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index db2968e6..183687ac 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -320,13 +320,13 @@ export class SearchAddon implements ITerminalAddon { break; } // Adjust the searchIndex to normalize emoji into single chars - const char = cell.char; + const char = cell.getChars(); if (char.length > 1) { resultIndex -= char.length - 1; } // Adjust the searchIndex for empty characters following wide unicode // chars (eg. CJK) - const charWidth = cell.width; + const charWidth = cell.getWidth(); if (charWidth === 0) { resultIndex++; } diff --git a/addons/xterm-addon-serialize/src/SerializeAddon.api.ts b/addons/xterm-addon-serialize/src/SerializeAddon.api.ts index c2a3c46e..a34aa0bd 100644 --- a/addons/xterm-addon-serialize/src/SerializeAddon.api.ts +++ b/addons/xterm-addon-serialize/src/SerializeAddon.api.ts @@ -126,7 +126,7 @@ describe('SerializeAddon', () => { const rows = 32; const cols = 10; const lines = newArray( - (index: number) => digitsString(cols, index, `\x1b[38;5;${index}m`), + (index: number) => digitsString(cols, index, `\x1b[38;5;${16 + index}m`), rows ); await writeSync(page, lines.join('\\r\\n')); @@ -256,7 +256,7 @@ describe('SerializeAddon', () => { assert.equal(await page.evaluate(`serializeAddon.serialize();`), lines.join('\r\n')); }); - it('serialize tabs correctly', async () => { + it('serialize tabs correctly', async () => { const lines = [ 'a\tb', 'aa\tc', @@ -311,9 +311,9 @@ const NORMAL = '0'; const FG_P16_RED = '31'; const FG_P16_GREEN = '32'; const FG_P16_YELLOW = '33'; -const FG_P256_RED = '38;5;1'; -const FG_P256_GREEN = '38;5;2'; -const FG_P256_YELLOW = '38;5;3'; +const FG_P256_RED = '38;5;196'; +const FG_P256_GREEN = '38;5;46'; +const FG_P256_YELLOW = '38;5;226'; const FG_RGB_RED = '38;2;255;0;0'; const FG_RGB_GREEN = '38;2;0;255;0'; const FG_RGB_YELLOW = '38;2;255;255;0'; @@ -323,9 +323,9 @@ const FG_RESET = '39'; const BG_P16_RED = '41'; const BG_P16_GREEN = '42'; const BG_P16_YELLOW = '43'; -const BG_P256_RED = '48;5;1'; -const BG_P256_GREEN = '48;5;2'; -const BG_P256_YELLOW = '48;5;3'; +const BG_P256_RED = '48;5;196'; +const BG_P256_GREEN = '48;5;46'; +const BG_P256_YELLOW = '48;5;226'; const BG_RGB_RED = '48;2;255;0;0'; const BG_RGB_GREEN = '48;2;0;255;0'; const BG_RGB_YELLOW = '48;2;255;255;0'; diff --git a/addons/xterm-addon-serialize/src/SerializeAddon.ts b/addons/xterm-addon-serialize/src/SerializeAddon.ts index b9c5ed4f..1d011726 100644 --- a/addons/xterm-addon-serialize/src/SerializeAddon.ts +++ b/addons/xterm-addon-serialize/src/SerializeAddon.ts @@ -104,15 +104,19 @@ class StringSerializeHandler extends BaseSerializeHandler { if (fgChanged) { const color = cell.getFgColor(); if (cell.isFgRGB()) { sgrSeq.push(38, 2, (color >>> 16) & 0xFF, (color >>> 8) & 0xFF, color & 0xFF); } - else if (cell.isFgPalette256()) { sgrSeq.push(38, 5, color); } - else if (cell.isFgPalette16()) { sgrSeq.push(color & 8 ? 90 + (color & 7) : 30 + (color & 7)); } + else if (cell.isFgPalette()) { + if (color >= 16) { sgrSeq.push(38, 5, color); } + else { sgrSeq.push(color & 8 ? 90 + (color & 7) : 30 + (color & 7)); } + } else { sgrSeq.push(39); } } if (bgChanged) { const color = cell.getBgColor(); if (cell.isBgRGB()) { sgrSeq.push(48, 2, (color >>> 16) & 0xFF, (color >>> 8) & 0xFF, color & 0xFF); } - else if (cell.isBgPalette256()) { sgrSeq.push(48, 5, color); } - else if (cell.isBgPalette16()) { sgrSeq.push(color & 8 ? 100 + (color & 7) : 40 + (color & 7)); } + else if (cell.isBgPalette()) { + if (color >= 16) { sgrSeq.push(48, 5, color); } + else { sgrSeq.push(color & 8 ? 100 + (color & 7) : 40 + (color & 7)); } + } else { sgrSeq.push(49); } } if (flagsChanged) { @@ -133,14 +137,14 @@ class StringSerializeHandler extends BaseSerializeHandler { // Count number of null cells encountered after the last non-null cell and move the cursor // if a non-null cell is found (eg. \t or cursor move) - if (cell.char === '') { + if (cell.getChars() === '') { this._nullCellCount++; } else if (this._nullCellCount > 0) { this._currentRow += `\x1b[${this._nullCellCount}C`; this._nullCellCount = 0; } - this._currentRow += cell.char; + this._currentRow += cell.getChars(); } protected _serializeString(): string { diff --git a/addons/xterm-addon-webgl/src/GlyphRenderer.ts b/addons/xterm-addon-webgl/src/GlyphRenderer.ts index 7b35949d..bc46a085 100644 --- a/addons/xterm-addon-webgl/src/GlyphRenderer.ts +++ b/addons/xterm-addon-webgl/src/GlyphRenderer.ts @@ -258,7 +258,7 @@ export class GlyphRenderer { if (!line) { line = terminal.buffer.getLine(row); } - const chars = line!.getCell(x)!.char; + const chars = line!.getCell(x)!.getChars(); this._updateCell(this._vertices.selectionAttributes, x, y, model.cells[offset], bg, model.cells[offset + RENDER_MODEL_FG_OFFSET], chars); } else { this._updateCell(this._vertices.selectionAttributes, x, y, model.cells[offset], bg, model.cells[offset + RENDER_MODEL_FG_OFFSET]); diff --git a/src/common/Types.d.ts b/src/common/Types.d.ts index 2dcc704b..33cc67d7 100644 --- a/src/common/Types.d.ts +++ b/src/common/Types.d.ts @@ -93,6 +93,7 @@ export interface IAttributeData { isBgPalette(): boolean; isFgDefault(): boolean; isBgDefault(): boolean; + isAttributeDefault(): boolean; // colors getFgColor(): number; diff --git a/src/common/buffer/AttributeData.ts b/src/common/buffer/AttributeData.ts index 0e7e2705..0b2679ee 100644 --- a/src/common/buffer/AttributeData.ts +++ b/src/common/buffer/AttributeData.ts @@ -47,6 +47,7 @@ export class AttributeData implements IAttributeData { public isBgPalette(): boolean { return (this.bg & Attributes.CM_MASK) === Attributes.CM_P16 || (this.bg & Attributes.CM_MASK) === Attributes.CM_P256; } public isFgDefault(): boolean { return (this.fg & Attributes.CM_MASK) === 0; } public isBgDefault(): boolean { return (this.bg & Attributes.CM_MASK) === 0; } + public isAttributeDefault(): boolean { return this.fg === 0 && this.bg === 0; } // colors public getFgColor(): number { diff --git a/src/common/buffer/Constants.ts b/src/common/buffer/Constants.ts index 81ac773a..276a5c54 100644 --- a/src/common/buffer/Constants.ts +++ b/src/common/buffer/Constants.ts @@ -116,12 +116,7 @@ export const enum FgFlags { BOLD = 0x8000000, UNDERLINE = 0x10000000, BLINK = 0x20000000, - INVISIBLE = 0x40000000, - - /** - * bit 27..31 (32th bit unused) - */ - FM_MASK = 0x7C000000 + INVISIBLE = 0x40000000 } export const enum BgFlags { @@ -129,10 +124,5 @@ export const enum BgFlags { * bit 27..32 (upper 4 unused) */ ITALIC = 0x4000000, - DIM = 0x8000000, - - /** - * bit 27..32 (upper 4 unused) - */ - FM_MASK = 0xFC000000 + DIM = 0x8000000 } diff --git a/src/public/Terminal.ts b/src/public/Terminal.ts index 5854cef6..fd61aaf2 100644 --- a/src/public/Terminal.ts +++ b/src/public/Terminal.ts @@ -5,9 +5,8 @@ import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings, ITerminalAddon, ISelectionPosition, IBuffer as IBufferApi, IBufferLine as IBufferLineApi, IBufferCell as IBufferCellApi, IParser, IFunctionIdentifier } from 'xterm'; import { ITerminal } from '../Types'; -import { IBufferLine } from 'common/Types'; +import { IBufferLine, ICellData } from 'common/Types'; import { IBuffer } from 'common/buffer/Types'; -import { Attributes } from 'common/buffer/Constants'; import { CellData } from 'common/buffer/CellData'; import { Terminal as TerminalCore } from '../Terminal'; import * as Strings from '../browser/LocalizableStrings'; @@ -203,7 +202,7 @@ class BufferApiView implements IBufferApi { } return new BufferLineApiView(line); } - public getNullCell(): IBufferCellApi { return new BufferCellApiView(new CellData()); } + public getNullCell(): IBufferCellApi { return new CellData(); } } class BufferLineApiView implements IBufferLineApi { @@ -211,59 +210,22 @@ class BufferLineApiView implements IBufferLineApi { public get isWrapped(): boolean { return this._line.isWrapped; } public get length(): number { return this._line.length; } - public getCell(x: number, cell?: BufferCellApiView): IBufferCellApi | undefined { + public getCell(x: number, cell?: IBufferCellApi): IBufferCellApi | undefined { if (x < 0 || x >= this._line.length) { return undefined; } if (cell) { - this._line.loadCell(x, cell.cell); + this._line.loadCell(x, cell); return cell; } - return new BufferCellApiView(this._line.loadCell(x, new CellData())); + return this._line.loadCell(x, new CellData()); } public translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string { return this._line.translateToString(trimRight, startColumn, endColumn); } } -class BufferCellApiView implements IBufferCellApi { - constructor(public cell: CellData) {} - - public get char(): string { return this.cell.getChars(); } - public get width(): number { return this.cell.getWidth(); } - - public getWidth(): number { return this.cell.getWidth(); } - public getChars(): string { return this.cell.getChars(); } - public getCode(): number { return this.cell.getCode(); } - - public isInverse(): number { return this.cell.isInverse(); } - public isBold(): number { return this.cell.isBold(); } - public isUnderline(): number { return this.cell.isUnderline(); } - public isBlink(): number { return this.cell.isBlink(); } - public isInvisible(): number { return this.cell.isInvisible(); } - public isItalic(): number { return this.cell.isItalic(); } - public isDim(): number { return this.cell.isDim(); } - - public getFgColorMode(): number { return this.cell.getFgColorMode(); } - public getBgColorMode(): number { return this.cell.getBgColorMode(); } - public isFgRGB(): boolean { return this.cell.isFgRGB(); } - public isBgRGB(): boolean { return this.cell.isBgRGB(); } - public isFgPalette(): boolean { return this.cell.isFgPalette(); } - public isBgPalette(): boolean { return this.cell.isBgPalette(); } - public isFgPalette16(): boolean { return this.cell.getFgColorMode() === Attributes.CM_P16; } - public isBgPalette16(): boolean { return this.cell.getBgColorMode() === Attributes.CM_P16; } - public isFgPalette256(): boolean { return this.cell.getFgColorMode() === Attributes.CM_P256; } - public isBgPalette256(): boolean { return this.cell.getBgColorMode() === Attributes.CM_P256; } - - public isAttributeDefault(): boolean { return this.cell.fg === 0 && this.cell.bg === 0; } - public isFgDefault(): boolean { return this.cell.isFgDefault(); } - public isBgDefault(): boolean { return this.cell.isBgDefault(); } - - public getFgColor(): number { return this.cell.getFgColor(); } - public getBgColor(): number { return this.cell.getBgColor(); } -} - class ParserApi implements IParser { constructor(private _core: ITerminal) {} diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 243266d0..c687b783 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -1007,20 +1007,6 @@ declare module 'xterm' { * Represents a single cell in the terminal's buffer. */ interface IBufferCell { - /** - * The character within the cell. - */ - readonly char: string; - - /** - * The width of the character. Some examples: - * - * - This is `1` for most cells. - * - This is `2` for wide character like CJK glyphs. - * - This is `0` for cells immediately following cells with a width of `2`. - */ - readonly width: number; - getWidth(): number; getChars(): string; getCode(): number; @@ -1042,10 +1028,6 @@ declare module 'xterm' { isBgRGB(): boolean; isFgPalette(): boolean; isBgPalette(): boolean; - isFgPalette16(): boolean; - isBgPalette16(): boolean; - isFgPalette256(): boolean; - isBgPalette256(): boolean; isAttributeDefault(): boolean; isFgDefault(): boolean; isBgDefault(): boolean;