fix(coding-agent): restore diff code block highlighting

closes #5092
This commit is contained in:
Armin Ronacher
2026-05-28 00:49:27 +02:00
parent 1e168a89c5
commit b85bf65678
3 changed files with 43 additions and 1 deletions

View File

@@ -1,4 +1,6 @@
import { describe, expect, it } from "vitest";
import { resetCapabilitiesCache, setCapabilities } from "@earendil-works/pi-tui";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { highlightCode, initTheme } from "../src/modes/interactive/theme/theme.ts";
import { highlight, renderHighlightedHtml, supportsLanguage } from "../src/utils/syntax-highlight.ts";
describe("syntax highlight renderer", () => {
@@ -46,3 +48,29 @@ describe("syntax highlight renderer", () => {
expect(rendered).toContain("[number:1]");
});
});
describe("theme syntax highlighting", () => {
beforeEach(() => {
setCapabilities({ images: null, trueColor: true, hyperlinks: false });
initTheme("dark");
});
afterEach(() => {
resetCapabilitiesCache();
});
it("colors diff additions and deletions in fenced diff blocks", () => {
const lines = highlightCode("-old\n+new\n", "diff");
expect(lines[0]).toBe("\x1b[38;2;204;102;102m-old\x1b[39m");
expect(lines[1]).toBe("\x1b[38;2;181;189;104m+new\x1b[39m");
});
it("keeps cli-highlight default styled scopes mapped to theme styles", () => {
expect(highlightCode("const re = /foo+/gi;", "javascript")[0]).toContain(
"\x1b[38;2;206;145;120m/foo+/gi\x1b[39m",
);
expect(highlightCode("@decorator", "python")[0]).toBe("\x1b[38;2;128;128;128m@decorator\x1b[39m");
expect(highlightCode("<div></div>", "html")[0]).toContain("\x1b[38;2;86;156;214mdiv\x1b[39m");
});
});