fix: align theme truecolor detection

This commit is contained in:
Armin Ronacher
2026-05-18 21:56:48 +02:00
parent f10cf57e96
commit dafcf61a34
4 changed files with 61 additions and 35 deletions

View File

@@ -1,10 +1,16 @@
import { describe, expect, it } from "vitest";
import { resetCapabilitiesCache, setCapabilities } from "@earendil-works/pi-tui";
import { afterEach, describe, expect, it } from "vitest";
import {
detectTerminalBackground,
getThemeByName,
getThemeForRgbColor,
parseOsc11BackgroundColor,
} from "../src/modes/interactive/theme/theme.js";
afterEach(() => {
resetCapabilitiesCache();
});
describe("detectTerminalBackground", () => {
it("uses the COLORFGBG background color index", () => {
expect(detectTerminalBackground({ env: { COLORFGBG: "0;15" } })).toMatchObject({
@@ -32,6 +38,22 @@ describe("detectTerminalBackground", () => {
});
});
describe("theme color mode", () => {
it("uses terminal capabilities", () => {
setCapabilities({ images: null, trueColor: false, hyperlinks: false });
const ansi256Theme = getThemeByName("dark");
if (!ansi256Theme) throw new Error("dark theme not found");
expect(ansi256Theme.getColorMode()).toBe("256color");
expect(ansi256Theme.getFgAnsi("accent")).toMatch(/^\x1b\[38;5;\d+m$/);
setCapabilities({ images: null, trueColor: true, hyperlinks: false });
const truecolorTheme = getThemeByName("dark");
if (!truecolorTheme) throw new Error("dark theme not found");
expect(truecolorTheme.getColorMode()).toBe("truecolor");
expect(truecolorTheme.getFgAnsi("accent")).toMatch(/^\x1b\[38;2;\d+;\d+;\d+m$/);
});
});
describe("parseOsc11BackgroundColor", () => {
it("parses 16-bit OSC 11 rgb responses", () => {
expect(parseOsc11BackgroundColor("\x1b]11;rgb:0000/8000/ffff\x07")).toEqual({ r: 0, g: 128, b: 255 });