diff --git a/src/bin.ts b/src/bin.ts
index 7593de9..caa3caf 100755
--- a/src/bin.ts
+++ b/src/bin.ts
@@ -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 } : {}) }));
}
diff --git a/src/config.ts b/src/config.ts
index 131495e..bc98faf 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -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");
diff --git a/src/model/settings.ts b/src/model/settings.ts
index 57d3627..08552d8 100644
--- a/src/model/settings.ts
+++ b/src/model/settings.ts
@@ -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. */
diff --git a/src/ui/DetailsPanel.tsx b/src/ui/DetailsPanel.tsx
index e002414..e336715 100644
--- a/src/ui/DetailsPanel.tsx
+++ b/src/ui/DetailsPanel.tsx
@@ -72,9 +72,9 @@ function Sections({ details, inner, loading, selected, onActivate }: { readonly
<>
{`PR #${branch.pullRequest.number} `}
- {branch.pullRequest.state}
+ {branch.pullRequest.state}
- {branch.pullRequest.checks ? {branch.pullRequest.checks.text} : null}
+ {branch.pullRequest.checks ? {branch.pullRequest.checks.text} : null}
{branch.pullRequest.title ? {truncate(branch.pullRequest.title, inner)} : null}
>
@@ -139,7 +139,7 @@ function Sections({ details, inner, loading, selected, onActivate }: { readonly
{truncate(automation.schedule, inner - automation.status.length - 1)}
- {automation.status}
+ {automation.status}
@@ -158,7 +158,7 @@ function Sections({ details, inner, loading, selected, onActivate }: { readonly
{details.goal ? (
{details.goal.objective}
- {details.goal.status}
+ {details.goal.status}
) : null}
>
diff --git a/src/ui/DiffView.tsx b/src/ui/DiffView.tsx
index 3eff80d..72ae633 100644
--- a/src/ui/DiffView.tsx
+++ b/src/ui/DiffView.tsx
@@ -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}
diff --git a/src/ui/PullRequestView.tsx b/src/ui/PullRequestView.tsx
index 676699d..56d8e18 100644
--- a/src/ui/PullRequestView.tsx
+++ b/src/ui/PullRequestView.tsx
@@ -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 = {
- 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 = {
+ 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
{view.lines.map((line, index) =>
line.kind === "title" && index > 0 ? (
-
+
{line.text}
) : line.kind === "title" ? (
@@ -54,7 +54,7 @@ export function PullRequestView(props: { readonly view: PullRequestViewState; re
) : /^https?:\/\//.test(line.text) ? (
) : (
-
+
{line.text || " "}
),
diff --git a/src/ui/ThreadList.tsx b/src/ui/ThreadList.tsx
index c4181e8..af626f9 100644
--- a/src/ui/ThreadList.tsx
+++ b/src/ui/ThreadList.tsx
@@ -77,7 +77,7 @@ export function ThreadList(props: {
{left}
- {right}
+ {right}
{attention ? {title} : title}
,
diff --git a/src/ui/ThreadView.tsx b/src/ui/ThreadView.tsx
index de556a0..5601189 100644
--- a/src/ui/ThreadView.tsx
+++ b/src/ui/ThreadView.tsx
@@ -302,9 +302,9 @@ function EventRow({ item, pending, onRespond }: { readonly onRespond: (decision:
if (!block) return null;
switch (block.kind) {
case "notice":
- return {block.text};
+ return {block.text};
case "tool":
- return {`${block.icon} ${block.label}`};
+ return {`${block.icon} ${block.label}`};
case "approval":
return {`Approval requested: ${block.title}`};
case "question":
diff --git a/src/ui/theme.ts b/src/ui/theme.ts
index f61f748..4f22108 100644
--- a/src/ui/theme.ts
+++ b/src/ui/theme.ts
@@ -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 = {
- 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 = {
- 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 = { 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 = { 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. */
diff --git a/test/config.test.ts b/test/config.test.ts
index e60d4c3..7943d3d 100644
--- a/test/config.test.ts
+++ b/test/config.test.ts
@@ -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");
});
});
diff --git a/test/theme.test.ts b/test/theme.test.ts
new file mode 100644
index 0000000..c75f865
--- /dev/null
+++ b/test/theme.test.ts
@@ -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);
+});