update cell color api design

This commit is contained in:
javacs3
2019-11-21 20:41:47 +08:00
parent ae70ef0fa2
commit cd5f3e9740
3 changed files with 201 additions and 185 deletions
+90 -26
View File
@@ -900,6 +900,13 @@ declare module 'xterm' {
* @param y The line index to get.
*/
getLine(y: number): IBufferLine | undefined;
/**
* Creates an empty cell object suitable as a cell reference in
* `line.getCell(x, cell)`. Use this to avoid costly recreation of
* cell objects when dealing with tons of cells.
*/
getNullCell(): IBufferCell;
}
/**
@@ -920,8 +927,9 @@ declare module 'xterm' {
* behavior.
*
* @param x The character index to get.
* @param cell Optional cell object to load data into.
*/
getCell(x: number): IBufferCell | undefined;
getCell(x: number, cell?: IBufferCell): IBufferCell | undefined;
/**
* Gets the line as a string. Note that this is gets only the string for the
@@ -934,6 +942,49 @@ declare module 'xterm' {
translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string;
}
/**
* Represents foreground and background color settings of a cell.
*/
interface IBufferCellColor {
/**
* Color mode of the color setting.
* RGB Color is an RGB color, use `.rgb` to grab the different channels.
* P256 Color is an indexed value of the 256 color palette.
* P16 Color is an indexed value of the 8 color palette (+8 for AIX bright colors).
* DEFAULT No color set, thus default color should be used.
*/
colorMode: 'RGB' | 'P256' | 'P16' | 'DEFAULT';
/**
* Color value set in the current color mode.
* Note that the color value can only be interpreted in conjunction
* with the color mode:
* RGB color contains 8 bit channels in RGB32 bitorder, e.g. red << 16 | green << 8 | blue
* P256 color contains indexed value 0..255
* P16 color contains indexed value 0..15
* DEFAULT color always contains -1
*/
color: number;
/**
* Helper to get RGB channels from color mode RGB. Reports channels as [red, green, blue].
*/
rgb: [number, number, number];
}
/**
* Represents style flags of a cell.
*/
interface IBufferCellFlags {
readonly bold: boolean;
readonly underline: boolean;
readonly blink: boolean;
readonly inverse: boolean;
readonly invisible: boolean;
readonly italic: boolean;
readonly dim: boolean;
}
/**
* Represents a single cell in the terminal's buffer.
*/
@@ -952,35 +1003,48 @@ declare module 'xterm' {
*/
readonly width: number;
readonly foregroundColor: CellColor;
readonly backgroundColor: CellColor;
readonly style: CellStyle;
}
/**
* Text attribute flags like bold, underline etc.
*/
readonly flags: IBufferCellFlags;
export enum CellStyle {
default,
// foreground style
inverse,
bold,
underline,
blink,
invisible,
// background style
italic,
dim
}
/**
* Foreground color.
*/
readonly fg: IBufferCellColor;
export class CellColor {
readonly type: 'default' | 'rgb' | 'palette16' | 'palette256';
readonly value: number;
/**
* Background color.
*/
readonly bg: IBufferCellColor;
constructor(value: number);
/**
* Whether cells have default attributes (flags and colors).
*/
isDefaultAttibutes(): boolean;
isDefault(): boolean;
equals(c: CellColor): boolean;
paletteId(): number;
rgbColor(): [number, number, number];
/**
* Whether cells have the same text attributes (flags and colors).
* @param other Other cell.
*/
equalAttibutes(other: IBufferCell): boolean;
static getDefault(): CellColor;
/**
* Whether cells have the same text attribute flags.
* @param other Other cell.
*/
equalFlags(other: IBufferCell): boolean;
/**
* Whether cells have the same foreground color.
* @param other Other cell.
*/
equalFg(other: IBufferCell): boolean;
/**
* Whether cells have the same background color.
* @param other Other cell.
*/
equalBg(other: IBufferCell): boolean;
}
}