Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "SerializeAsHTML(): Fallback to default ansi colors when running headless terminal" #4333

Merged
merged 1 commit into from Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 1 addition & 21 deletions addons/xterm-addon-serialize/src/SerializeAddon.test.ts
Expand Up @@ -74,7 +74,7 @@ describe('xterm-addon-serialize', () => {
terminal = new Terminal({ cols: 10, rows: 2, allowProposedApi: true });
terminal.loadAddon(serializeAddon);

(terminal as any)._core._themeService = new ThemeService((terminal as any)._core.optionsService);
(terminal as any)._core._themeService = new ThemeService(new OptionsService({}));
(terminal as any)._core._selectionService = new TestSelectionService((terminal as any)._core._bufferService);
});

Expand Down Expand Up @@ -205,25 +205,5 @@ describe('xterm-addon-serialize', () => {
});
assert.equal((output.match(/color: #ffffff; background-color: #000000; font-family: courier-new, courier, monospace; font-size: 15px;/g) || []).length, 1, output);
});

it('cells with custom color styling', async () => {
terminal.options.theme.black = '#ffa500';
terminal.options.theme = { ... terminal.options.theme };

await writeP(terminal, ' ' + sgr('38;5;0') + 'terminal' + sgr('39') + ' ');

const output = serializeAddon.serializeAsHTML();
assert.equal((output.match(/<span style='color: #ffa500;'>terminal<\/span>/g) || []).length, 1, output);
});

it('cells with color styling - xterm headless', async () => {
// a headless terminal doesn't have a themeservice
(terminal as any)._core._themeService = undefined;

await writeP(terminal, ' ' + sgr('38;5;46') + 'terminal' + sgr('39') + ' ');

const output = serializeAddon.serializeAsHTML();
assert.equal((output.match(/<span style='color: #00ff00;'>terminal<\/span>/g) || []).length, 1, output);
});
});
});
16 changes: 5 additions & 11 deletions addons/xterm-addon-serialize/src/SerializeAddon.ts
Expand Up @@ -7,8 +7,7 @@

import { Terminal, ITerminalAddon, IBuffer, IBufferCell, IBufferRange } from 'xterm';
import { IColorSet } from 'browser/Types';
import { IAttributeData, IColor } from 'common/Types';
import { DEFAULT_ANSI_COLORS } from 'browser/services/ThemeService';
import { IAttributeData } from 'common/Types';

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

private _htmlContent = '';

private _ansiColors: Readonly<IColor[]>;
private _colors: IColorSet;

constructor(
buffer: IBuffer,
Expand All @@ -544,13 +543,8 @@ export class HTMLSerializeHandler extends BaseSerializeHandler {
) {
super(buffer);

// For xterm headless: fallback to ansi colors
if ((_terminal as any)._core._themeService) {
this._ansiColors = (_terminal as any)._core._themeService.colors.ansi;
}
else {
this._ansiColors = DEFAULT_ANSI_COLORS;
}
// https://github.com/xtermjs/xterm.js/issues/3601
this._colors = (_terminal as any)._core._themeService.colors;
}

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