Skip to content

Commit 3a81ef5

Browse files
authored
Revert "SerializeAsHTML(): Fallback to default ansi colors when running headless terminal"
1 parent 6cfdcb1 commit 3a81ef5

File tree

2 files changed

+6
-32
lines changed

2 files changed

+6
-32
lines changed

addons/xterm-addon-serialize/src/SerializeAddon.test.ts

+1-21
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('xterm-addon-serialize', () => {
7474
terminal = new Terminal({ cols: 10, rows: 2, allowProposedApi: true });
7575
terminal.loadAddon(serializeAddon);
7676

77-
(terminal as any)._core._themeService = new ThemeService((terminal as any)._core.optionsService);
77+
(terminal as any)._core._themeService = new ThemeService(new OptionsService({}));
7878
(terminal as any)._core._selectionService = new TestSelectionService((terminal as any)._core._bufferService);
7979
});
8080

@@ -205,25 +205,5 @@ describe('xterm-addon-serialize', () => {
205205
});
206206
assert.equal((output.match(/color: #ffffff; background-color: #000000; font-family: courier-new, courier, monospace; font-size: 15px;/g) || []).length, 1, output);
207207
});
208-
209-
it('cells with custom color styling', async () => {
210-
terminal.options.theme.black = '#ffa500';
211-
terminal.options.theme = { ... terminal.options.theme };
212-
213-
await writeP(terminal, ' ' + sgr('38;5;0') + 'terminal' + sgr('39') + ' ');
214-
215-
const output = serializeAddon.serializeAsHTML();
216-
assert.equal((output.match(/<span style='color: #ffa500;'>terminal<\/span>/g) || []).length, 1, output);
217-
});
218-
219-
it('cells with color styling - xterm headless', async () => {
220-
// a headless terminal doesn't have a themeservice
221-
(terminal as any)._core._themeService = undefined;
222-
223-
await writeP(terminal, ' ' + sgr('38;5;46') + 'terminal' + sgr('39') + ' ');
224-
225-
const output = serializeAddon.serializeAsHTML();
226-
assert.equal((output.match(/<span style='color: #00ff00;'>terminal<\/span>/g) || []).length, 1, output);
227-
});
228208
});
229209
});

addons/xterm-addon-serialize/src/SerializeAddon.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
import { Terminal, ITerminalAddon, IBuffer, IBufferCell, IBufferRange } from 'xterm';
99
import { IColorSet } from 'browser/Types';
10-
import { IAttributeData, IColor } from 'common/Types';
11-
import { DEFAULT_ANSI_COLORS } from 'browser/services/ThemeService';
10+
import { IAttributeData } from 'common/Types';
1211

1312
function constrain(value: number, low: number, high: number): number {
1413
return Math.max(low, Math.min(value, high));
@@ -535,7 +534,7 @@ export class HTMLSerializeHandler extends BaseSerializeHandler {
535534

536535
private _htmlContent = '';
537536

538-
private _ansiColors: Readonly<IColor[]>;
537+
private _colors: IColorSet;
539538

540539
constructor(
541540
buffer: IBuffer,
@@ -544,13 +543,8 @@ export class HTMLSerializeHandler extends BaseSerializeHandler {
544543
) {
545544
super(buffer);
546545

547-
// For xterm headless: fallback to ansi colors
548-
if ((_terminal as any)._core._themeService) {
549-
this._ansiColors = (_terminal as any)._core._themeService.colors.ansi;
550-
}
551-
else {
552-
this._ansiColors = DEFAULT_ANSI_COLORS;
553-
}
546+
// https://github.com/xtermjs/xterm.js/issues/3601
547+
this._colors = (_terminal as any)._core._themeService.colors;
554548
}
555549

556550
private _padStart(target: string, targetLength: number, padString: string): string {
@@ -606,7 +600,7 @@ export class HTMLSerializeHandler extends BaseSerializeHandler {
606600
return rgb.map(x => this._padStart(x.toString(16), 2, '0')).join('');
607601
}
608602
if (isFg ? cell.isFgPalette() : cell.isBgPalette()) {
609-
return this._ansiColors[color].css;
603+
return this._colors.ansi[color].css;
610604
}
611605
return undefined;
612606
}

0 commit comments

Comments
 (0)