Light palette, chosen from the terminal's background or the Colours setting

This commit is contained in:
Callum Alpass committed 2026-11-02 23:21:55 +11:00
1 parent 3ef67c5b50
commit 49fc25f7a2
11 files changed
+91 -42

No files matched your search

+3
View File
@@ -145,6 +145,9 @@ async function runUi(attachNeedle?: string) {
const layout = await loadLayout();
// The kitty keyboard protocol lets terminals that support it send shift+enter, for newlines.
const renderer = await createCliRenderer({ exitOnCtrlC: false, useMouse: true, useKittyKeyboard: {} });
const { applyTheme } = await import("./ui/theme.ts");
// Terminals that don't say what their background is get the dark palette.
applyTheme(config.theme === "auto" ? ((await renderer.waitForThemeMode(300)) ?? "dark") : config.theme);
createRoot(renderer).render(createElement(App, { session, config, layout, ...(attachThreadId ? { attachThreadId } : {}) }));
}
+4 -1
View File
@@ -18,9 +18,11 @@ export interface Tui3Config {
readonly notificationMode: "off" | "notifications" | "sound" | "notifications-and-sound";
/** As the web's in-app toasts: a line at the bottom for threads you aren't looking at. */
readonly inAppNotificationsEnabled: boolean;
/** auto follows the terminal's background colour. */
readonly theme: "auto" | "dark" | "light";
}
export const DEFAULT_CONFIG: Tui3Config = { followUpBehavior: "steer", sendShortcut: "enter", timestampFormat: "locale", diffIgnoreWhitespace: true, notificationMode: "sound", inAppNotificationsEnabled: true };
export const DEFAULT_CONFIG: Tui3Config = { followUpBehavior: "steer", sendShortcut: "enter", timestampFormat: "locale", diffIgnoreWhitespace: true, notificationMode: "sound", inAppNotificationsEnabled: true, theme: "auto" };
/** Every setting with its choices in cycling order, for the settings view. */
export const CONFIG_CHOICES: { readonly [K in keyof Tui3Config]: readonly Tui3Config[K][] } = {
@@ -30,6 +32,7 @@ export const CONFIG_CHOICES: { readonly [K in keyof Tui3Config]: readonly Tui3Co
diffIgnoreWhitespace: [true, false],
notificationMode: ["off", "sound", "notifications", "notifications-and-sound"],
inAppNotificationsEnabled: [true, false],
theme: ["auto", "dark", "light"],
};
export const configPath = () => join(configDir(), "config.json");
+1
View File
@@ -21,6 +21,7 @@ const LABELS: { readonly [K in keyof Tui3Config]: { readonly label: string; read
values: { off: "off", sound: "bell", notifications: "desktop notifications", "notifications-and-sound": "bell and desktop notifications" },
},
inAppNotificationsEnabled: { label: "In-app alerts", help: "a line at the bottom for other threads", values: { true: "on", false: "off" } },
theme: { label: "Colours", help: "from the next start", values: { auto: "match the terminal", dark: "dark", light: "light" } },
};
/** tui3's own settings, in display order, each cycled with enter. */
+4 -4
View File
@@ -72,9 +72,9 @@ function Sections({ details, inner, loading, selected, onActivate }: { readonly
<>
<box flexDirection="row">
<text fg={colors.text}>{`PR #${branch.pullRequest.number} `}</text>
<text fg={statusColor[branch.pullRequest.tone]}>{branch.pullRequest.state}</text>
<text fg={statusColor(branch.pullRequest.tone)}>{branch.pullRequest.state}</text>
<box flexGrow={1} />
{branch.pullRequest.checks ? <text fg={statusColor[branch.pullRequest.checks.tone]}>{branch.pullRequest.checks.text}</text> : null}
{branch.pullRequest.checks ? <text fg={statusColor(branch.pullRequest.checks.tone)}>{branch.pullRequest.checks.text}</text> : null}
</box>
{branch.pullRequest.title ? <text fg={colors.muted}>{truncate(branch.pullRequest.title, inner)}</text> : null}
</>
@@ -139,7 +139,7 @@ function Sections({ details, inner, loading, selected, onActivate }: { readonly
<box flexDirection="row">
<text fg={colors.faint}>{truncate(automation.schedule, inner - automation.status.length - 1)}</text>
<box flexGrow={1} />
<text fg={statusColor[automation.tone]}>{automation.status}</text>
<text fg={statusColor(automation.tone)}>{automation.status}</text>
</box>
</box>
</Selectable>
@@ -158,7 +158,7 @@ function Sections({ details, inner, loading, selected, onActivate }: { readonly
{details.goal ? (
<Section title="Goal">
<text fg={colors.text}>{details.goal.objective}</text>
<text fg={statusColor[details.goal.tone]}>{details.goal.status}</text>
<text fg={statusColor(details.goal.tone)}>{details.goal.status}</text>
</Section>
) : null}
</>
+4 -4
View File
@@ -49,10 +49,10 @@ export function DiffView(props: { readonly diff: DiffState; readonly scrollRef:
showLineNumbers
wrapMode="none"
fg={colors.text}
addedBg="#1e2a1e"
removedBg="#2d1f24"
addedContentBg="#1e2a1e"
removedContentBg="#2d1f24"
addedBg={colors.diffAddedBg}
removedBg={colors.diffRemovedBg}
addedContentBg={colors.diffAddedBg}
removedContentBg={colors.diffRemovedBg}
addedSignColor={colors.good}
removedSignColor={colors.bad}
lineNumberFg={colors.faint}
+12 -12
View File
@@ -3,7 +3,7 @@ import type { RefObject } from "react";
import type { PullRequestLine } from "../model/pullRequests.ts";
import { Button, isLeftClick, isRightClick, useHover } from "./Button.tsx";
import { colors } from "./theme.ts";
import { colors, type Palette } from "./theme.ts";
export interface PullRequestViewState {
readonly status: "loading" | "ready" | "error";
@@ -12,15 +12,15 @@ export interface PullRequestViewState {
readonly error?: string;
}
const LINE_COLORS: Record<PullRequestLine["kind"], string> = {
title: colors.accent,
meta: colors.muted,
body: colors.text,
check: colors.text,
review: colors.text,
comment: colors.muted,
guide: colors.text,
faint: colors.faint,
const LINE_COLORS: Record<PullRequestLine["kind"], keyof Palette> = {
title: "accent",
meta: "muted",
body: "text",
check: "text",
review: "text",
comment: "muted",
guide: "text",
faint: "faint",
};
/** A linked pull request in place of the conversation: j/k scroll, o opens it, esc closes. */
@@ -44,7 +44,7 @@ export function PullRequestView(props: { readonly view: PullRequestViewState; re
<scrollbox ref={props.scrollRef} flexGrow={1} minHeight={0}>
{view.lines.map((line, index) =>
line.kind === "title" && index > 0 ? (
<text key={index} fg={LINE_COLORS[line.kind]} marginTop={1}>
<text key={index} fg={colors[LINE_COLORS[line.kind]]} marginTop={1}>
<strong>{line.text}</strong>
</text>
) : line.kind === "title" ? (
@@ -54,7 +54,7 @@ export function PullRequestView(props: { readonly view: PullRequestViewState; re
) : /^https?:\/\//.test(line.text) ? (
<Link key={index} text={line.text} onPress={props.onOpenUrl} />
) : (
<text key={index} fg={line.kind === "check" ? checkColor(line.text) : LINE_COLORS[line.kind]}>
<text key={index} fg={line.kind === "check" ? checkColor(line.text) : colors[LINE_COLORS[line.kind]]}>
{line.text || " "}
</text>
),
+1 -1
View File
@@ -77,7 +77,7 @@ export function ThreadList(props: {
<box flexDirection="row">
<text fg={colors.faint}>{left}</text>
<box flexGrow={1} />
<text fg={status ? statusColor[status.tone] : colors.faint}>{right}</text>
<text fg={status ? statusColor(status.tone) : colors.faint}>{right}</text>
</box>
<text fg={recede ? colors.muted : colors.text}>{attention ? <strong>{title}</strong> : title}</text>
</ClickRow>,
+2 -2
View File
@@ -302,9 +302,9 @@ function EventRow({ item, pending, onRespond }: { readonly onRespond: (decision:
if (!block) return null;
switch (block.kind) {
case "notice":
return <text marginTop={1} fg={toneColor[block.tone]}>{block.text}</text>;
return <text marginTop={1} fg={toneColor(block.tone)}>{block.text}</text>;
case "tool":
return <text marginTop={1} fg={toneColor[block.tone]}>{`${block.icon} ${block.label}`}</text>;
return <text marginTop={1} fg={toneColor(block.tone)}>{`${block.icon} ${block.label}`}</text>;
case "approval":
return <text marginTop={1} fg={colors.muted}>{`Approval requested: ${block.title}`}</text>;
case "question":
+44 -17
View File
@@ -1,9 +1,10 @@
import { SyntaxStyle } from "@opentui/core";
import { SyntaxStyle, type ThemeMode } from "@opentui/core";
import type { StatusTone } from "../model/threads.ts";
import type { Tone } from "../model/transcript.ts";
export const colors = {
/** Tokyo Night. */
const DARK = {
bg: "#16161e",
panel: "#1a1b26",
border: "#2f334d",
@@ -25,25 +26,51 @@ export const colors = {
info: "#7dcfff",
input: "#bb9af7",
plan: "#c099ff",
} as const;
export const statusColor: Record<StatusTone, string> = {
info: colors.info,
muted: colors.muted,
warn: colors.warn,
input: colors.input,
bad: colors.bad,
good: colors.good,
diffAddedBg: "#1e2a1e",
diffRemovedBg: "#2d1f24",
};
export const toneColor: Record<Tone, string> = {
normal: colors.text,
muted: colors.muted,
good: colors.good,
bad: colors.bad,
warn: colors.warn,
export type Palette = { readonly [K in keyof typeof DARK]: string };
/** Tokyo Night Day, for terminals with a light background. */
const LIGHT: Palette = {
bg: "#e1e2e7",
panel: "#d6d9e4",
border: "#a8aecb",
borderFocused: "#2e7de9",
text: "#343b58",
muted: "#5f6893",
faint: "#7a81a8",
accent: "#2e7de9",
user: "#007197",
userBg: "#d0d5e3",
good: "#587539",
bad: "#d20f39",
warn: "#8c6c3e",
selectedBg: "#b7c1e3",
hoverBg: "#d3d6e2",
buttonBg: "#c4c8da",
info: "#007197",
input: "#9854f1",
plan: "#7847bd",
diffAddedBg: "#d4e6cc",
diffRemovedBg: "#f1d3da",
};
/** The palette in use. Read at render time, so applyTheme before the first frame sets it everywhere. */
export const colors: Palette = { ...DARK };
export function applyTheme(mode: ThemeMode): void {
Object.assign(colors, mode === "light" ? LIGHT : DARK);
markdownStyle = undefined;
}
const STATUS_COLORS: Record<StatusTone, keyof Palette> = { info: "info", muted: "muted", warn: "warn", input: "input", bad: "bad", good: "good" };
export const statusColor = (tone: StatusTone): string => colors[STATUS_COLORS[tone]];
const TONE_COLORS: Record<Tone, keyof Palette> = { normal: "text", muted: "muted", good: "good", bad: "bad", warn: "warn" };
export const toneColor = (tone: Tone): string => colors[TONE_COLORS[tone]];
let markdownStyle: SyntaxStyle | undefined;
/** Created lazily: SyntaxStyle needs the native renderer library loaded. */
+1 -1
View File
@@ -28,7 +28,7 @@ describe("config", () => {
test("labels settings for the settings view", () => {
const rows = settingRows({ ...DEFAULT_CONFIG, followUpBehavior: "queue" });
expect(rows.map((row) => row.key)).toEqual(["followUpBehavior", "sendShortcut", "timestampFormat", "diffIgnoreWhitespace", "notificationMode", "inAppNotificationsEnabled"]);
expect(rows.map((row) => row.key)).toEqual(["followUpBehavior", "sendShortcut", "timestampFormat", "diffIgnoreWhitespace", "notificationMode", "inAppNotificationsEnabled", "theme"]);
expect(rows[0]?.value).toBe("queues");
});
});
+15
View File
@@ -0,0 +1,15 @@
import { afterEach, expect, test } from "bun:test";
import { applyTheme, colors, statusColor, toneColor } from "../src/ui/theme.ts";
afterEach(() => applyTheme("dark"));
test("the light palette replaces every colour, and the tone maps follow it", () => {
const dark = { ...colors };
applyTheme("light");
for (const key of Object.keys(dark) as (keyof typeof dark)[]) expect(colors[key]).not.toBe(dark[key]);
expect(statusColor("bad")).toBe(colors.bad);
expect(toneColor("normal")).toBe(colors.text);
applyTheme("dark");
expect(colors).toEqual(dark);
});