T1: four more themes, theme picker, theme file import, editor font settings

Plum Night, River, Paper and Reed (designed by Amy, approved by Daniel)
join the brand pair. theme.list/current/select/import, a picker with
live preview (view.selectTheme) and "Import Theme…" (view.importTheme);
imported themes are validated and stored in <data_dir>/themes. Editor
font family and line height settings apply live. Docs: docs/themes.md.

Gate: fmt, clippy and the rest pass up to cargo test, where only the
unrelated lutra-terminal PTY test a_full_buffer_stops_the_shell timed
out under load; to be re-run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-11-02 19:47:58 +01:00
parent 872b5cb258
commit 086bc8a925
26 changed files with 2881 additions and 100 deletions

View file

@ -106,21 +106,24 @@ const KIND_PAIRS: [string, string, number][] = [...new Set(Object.values(KIND_CO
/** ANSI colour names, as in `TERMINAL_TOKENS` in `theme.rs`. */
const ANSI = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"] as const;
/** ANSI tokens that may blend into the background, per theme id. */
const TERMINAL_EXEMPT: Record<string, readonly string[]> = {
"lutra-dark": ["terminal-ansi-black"],
"lutra-light": ["terminal-ansi-white", "terminal-ansi-bright-white"],
};
/**
* ANSI tokens that may blend into the background: black in dark themes,
* white and bright white in light ones.
*/
const TERMINAL_EXEMPT = {
dark: ["terminal-ansi-black"],
light: ["terminal-ansi-white", "terminal-ansi-bright-white"],
} as const;
/**
* The terminal's pairs for one theme: text and selection, the cursor, and
* every ANSI colour (normal and bright) that is not exempt.
*
* @param id - the theme id.
* @param dark - whether the theme is dark.
* @returns foreground token, background token and minimum ratio.
*/
function terminalPairs(id: string): [string, string, number][] {
const exempt = TERMINAL_EXEMPT[id] ?? [];
function terminalPairs(dark: boolean): [string, string, number][] {
const exempt: readonly string[] = TERMINAL_EXEMPT[dark ? "dark" : "light"];
const ansi = ANSI.flatMap((name) => [`terminal-ansi-${name}`, `terminal-ansi-bright-${name}`]).filter(
(name) => !exempt.includes(name),
);
@ -162,6 +165,27 @@ export function contrast(a: string, b: string): number {
return (hi + 0.05) / (lo + 0.05);
}
describe("built-in themes", () => {
it("are the brand pair and the four C9 themes, two of each kind added", () => {
expect(themes.map((theme) => theme.id)).toEqual([
"lutra-dark",
"lutra-light",
"lutra-plum-night",
"lutra-river",
"lutra-paper",
"lutra-reed",
]);
expect(themes.filter((theme) => theme.dark)).toHaveLength(3);
});
it("all define the same tokens", () => {
const names = (tokens: Record<string, string>): string[] => Object.keys(tokens).sort();
for (const theme of themes) {
expect(names(theme.tokens)).toEqual(names(themes[0]?.tokens ?? {}));
}
});
});
describe("contrast helper", () => {
it("matches the WCAG extremes", () => {
expect(contrast("#000000", "#ffffff")).toBeCloseTo(21, 5);
@ -203,7 +227,7 @@ describe.each(themes)("theme $id", (theme) => {
expect(defined).toHaveLength(ANSI.length * 2);
});
it.each([...PAIRS, ...SYNTAX_PAIRS, ...STATUS_PAIRS, ...TAB_STATUS_PAIRS, ...KIND_PAIRS, ...terminalPairs(theme.id)])("%s on %s reaches %d:1", (fg, bg, min) => {
it.each([...PAIRS, ...SYNTAX_PAIRS, ...STATUS_PAIRS, ...TAB_STATUS_PAIRS, ...KIND_PAIRS, ...terminalPairs(theme.dark)])("%s on %s reaches %d:1", (fg, bg, min) => {
expect(contrast(token(fg), token(bg))).toBeGreaterThanOrEqual(min);
});
});