From f96967ab722fe74eafed6dfdf6f3cbcbc5a4a0fc Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 4 Jun 2026 00:51:35 -0500 Subject: [PATCH] test: failing repro for color-encoding-modes --- test/color-encoding-modes.test.ts | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/color-encoding-modes.test.ts diff --git a/test/color-encoding-modes.test.ts b/test/color-encoding-modes.test.ts new file mode 100644 index 0000000..081a15f --- /dev/null +++ b/test/color-encoding-modes.test.ts @@ -0,0 +1,41 @@ +import { describe, expect, it } from "./suite.ts"; +import { createTerm } from "../term.ts"; +import { close, grow, open, rgba, text } from "../ops.ts"; + +const decode = (b: Uint8Array) => new TextDecoder().decode(b); + +describe("color encoding modes", () => { + it("16-color mode downgrades standard red foreground to 4-bit", async () => { + let term = await createTerm({ width: 4, height: 1 }); + let ansi = decode( + term.render([ + open("root", { layout: { width: grow(), height: grow() } }), + text("X", { color: rgba(255, 0, 0) }), + close(), + // deno-lint-ignore no-explicit-any + ], { colorMode: "16" } as any).output, + ); + + let before = ansi.slice(0, ansi.indexOf("X")); + // pins: standard-palette red maps to 4-bit \x1b[31m under colorMode:"16" + expect(before).toContain("\x1b[31m"); + // pins: the 24-bit sequence must not survive the downgrade + expect(before).not.toContain("\x1b[38;2;255;0;0"); + }); + + it("256-color mode downgrades standard red foreground to a palette index", async () => { + let term = await createTerm({ width: 4, height: 1 }); + let ansi = decode( + term.render([ + open("root", { layout: { width: grow(), height: grow() } }), + text("X", { color: rgba(255, 0, 0) }), + close(), + // deno-lint-ignore no-explicit-any + ], { colorMode: "256" } as any).output, + ); + + let before = ansi.slice(0, ansi.indexOf("X")); + // pins: standard-palette red maps to index 1 (\x1b[38;5;1m) under colorMode:"256" + expect(before).toContain("\x1b[38;5;1m"); + }); +}); -- 2.51.2