mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
fix cell.getFgColor/getBgColor return color256 code even it's color16
mode leading to serialize return wrong sequence
This commit is contained in:
@@ -131,12 +131,14 @@ describe('SerializeAddon', () => {
|
||||
|
||||
it('serialize all rows of content with color16', async function (): Promise<any> {
|
||||
this.timeout(20000);
|
||||
const rows = 16;
|
||||
const cols = 10;
|
||||
const color16 = [
|
||||
30, 31, 32, 33, 34, 35, 36, 37, // Set foreground color
|
||||
40, 41, 42, 43, 44, 45, 46, 47 // Set background color
|
||||
90, 91, 92, 93, 94, 95, 96, 97,
|
||||
40, 41, 42, 43, 44, 45, 46, 47, // Set background color
|
||||
100, 101, 103, 104, 105, 106, 107
|
||||
];
|
||||
const rows = color16.length;
|
||||
const lines = newArray<string>(
|
||||
(index: number) => digitsString(cols, index, `\x1b[${color16[index % color16.length]}m`),
|
||||
rows
|
||||
|
||||
@@ -77,6 +77,24 @@ const FG_FM_MASK = FgFlags.FM_MASK;
|
||||
const BG_FM_MASK = BgFlags.FM_MASK;
|
||||
const COLOR_MASK = Attributes.CM_MASK | Attributes.RGB_MASK;
|
||||
|
||||
function fgColor256to16(c: number): number {
|
||||
if (0 <= c && c <= 7) {
|
||||
return 30 + c;
|
||||
} else if (8 <= c && c <= 15) {
|
||||
return 82 + c;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
function bgColor256to16(c: number): number {
|
||||
if (0 <= c && c <= 7) {
|
||||
return 40 + c;
|
||||
} else if (8 <= c && c <= 15) {
|
||||
return 92 + c;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
class StringSerializeHandler extends BaseSerializeHandler {
|
||||
private _rowIndex: number = 0;
|
||||
private _allRows: string[] = new Array<string>();
|
||||
@@ -130,7 +148,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
|
||||
sgrSeq.push('39');
|
||||
} else if (cell.isFgPalette()) {
|
||||
switch (cell.getFgColorMode()) {
|
||||
case Attributes.CM_P16: sgrSeq.push(`${30 + fgColor}`); break;
|
||||
case Attributes.CM_P16: sgrSeq.push(fgColor256to16(fgColor).toString()); break;
|
||||
case Attributes.CM_P256: sgrSeq.push(`38;5;${fgColor}`); break;
|
||||
}
|
||||
} else if (cell.isFgRGB()) {
|
||||
@@ -165,7 +183,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
|
||||
sgrSeq.push('49');
|
||||
} else if (cell.isBgPalette()) {
|
||||
switch (cell.getBgColorMode()) {
|
||||
case Attributes.CM_P16: sgrSeq.push(`${40 + bgColor}`); break;
|
||||
case Attributes.CM_P16: sgrSeq.push(bgColor256to16(bgColor).toString()); break;
|
||||
case Attributes.CM_P256: sgrSeq.push(`48;5;${bgColor}`); break;
|
||||
}
|
||||
} else if (cell.isFgRGB()) {
|
||||
|
||||
Reference in New Issue
Block a user