Light palette, chosen from the terminal's background or the Colours setting
This commit is contained in:
1 parent
3ef67c5b50
commit
49fc25f7a2
11 files changed
+91
-42
No files matched your search
@@ -145,6 +145,9 @@ async function runUi(attachNeedle?: string) {
|
|||||||
const layout = await loadLayout();
|
const layout = await loadLayout();
|
||||||
// The kitty keyboard protocol lets terminals that support it send shift+enter, for newlines.
|
// The kitty keyboard protocol lets terminals that support it send shift+enter, for newlines.
|
||||||
const renderer = await createCliRenderer({ exitOnCtrlC: false, useMouse: true, useKittyKeyboard: {} });
|
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 } : {}) }));
|
createRoot(renderer).render(createElement(App, { session, config, layout, ...(attachThreadId ? { attachThreadId } : {}) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -18,9 +18,11 @@ export interface Tui3Config {
|
|||||||
readonly notificationMode: "off" | "notifications" | "sound" | "notifications-and-sound";
|
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. */
|
/** As the web's in-app toasts: a line at the bottom for threads you aren't looking at. */
|
||||||
readonly inAppNotificationsEnabled: boolean;
|
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. */
|
/** Every setting with its choices in cycling order, for the settings view. */
|
||||||
export const CONFIG_CHOICES: { readonly [K in keyof Tui3Config]: readonly Tui3Config[K][] } = {
|
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],
|
diffIgnoreWhitespace: [true, false],
|
||||||
notificationMode: ["off", "sound", "notifications", "notifications-and-sound"],
|
notificationMode: ["off", "sound", "notifications", "notifications-and-sound"],
|
||||||
inAppNotificationsEnabled: [true, false],
|
inAppNotificationsEnabled: [true, false],
|
||||||
|
theme: ["auto", "dark", "light"],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const configPath = () => join(configDir(), "config.json");
|
export const configPath = () => join(configDir(), "config.json");
|
||||||
|
|||||||
@@ -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" },
|
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" } },
|
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. */
|
/** tui3's own settings, in display order, each cycled with enter. */
|
||||||
|
|||||||
@@ -72,9 +72,9 @@ function Sections({ details, inner, loading, selected, onActivate }: { readonly
|
|||||||
<>
|
<>
|
||||||
<box flexDirection="row">
|
<box flexDirection="row">
|
||||||
<text fg={colors.text}>{`PR #${branch.pullRequest.number} `}</text>
|
<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} />
|
<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>
|
</box>
|
||||||
{branch.pullRequest.title ? <text fg={colors.muted}>{truncate(branch.pullRequest.title, inner)}</text> : null}
|
{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">
|
<box flexDirection="row">
|
||||||
<text fg={colors.faint}>{truncate(automation.schedule, inner - automation.status.length - 1)}</text>
|
<text fg={colors.faint}>{truncate(automation.schedule, inner - automation.status.length - 1)}</text>
|
||||||
<box flexGrow={1} />
|
<box flexGrow={1} />
|
||||||
<text fg={statusColor[automation.tone]}>{automation.status}</text>
|
<text fg={statusColor(automation.tone)}>{automation.status}</text>
|
||||||
</box>
|
</box>
|
||||||
</box>
|
</box>
|
||||||
</Selectable>
|
</Selectable>
|
||||||
@@ -158,7 +158,7 @@ function Sections({ details, inner, loading, selected, onActivate }: { readonly
|
|||||||
{details.goal ? (
|
{details.goal ? (
|
||||||
<Section title="Goal">
|
<Section title="Goal">
|
||||||
<text fg={colors.text}>{details.goal.objective}</text>
|
<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>
|
</Section>
|
||||||
) : null}
|
) : null}
|
||||||
</>
|
</>
|
||||||
|
|||||||
+4
-4
@@ -49,10 +49,10 @@ export function DiffView(props: { readonly diff: DiffState; readonly scrollRef:
|
|||||||
showLineNumbers
|
showLineNumbers
|
||||||
wrapMode="none"
|
wrapMode="none"
|
||||||
fg={colors.text}
|
fg={colors.text}
|
||||||
addedBg="#1e2a1e"
|
addedBg={colors.diffAddedBg}
|
||||||
removedBg="#2d1f24"
|
removedBg={colors.diffRemovedBg}
|
||||||
addedContentBg="#1e2a1e"
|
addedContentBg={colors.diffAddedBg}
|
||||||
removedContentBg="#2d1f24"
|
removedContentBg={colors.diffRemovedBg}
|
||||||
addedSignColor={colors.good}
|
addedSignColor={colors.good}
|
||||||
removedSignColor={colors.bad}
|
removedSignColor={colors.bad}
|
||||||
lineNumberFg={colors.faint}
|
lineNumberFg={colors.faint}
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ import type { RefObject } from "react";
|
|||||||
|
|
||||||
import type { PullRequestLine } from "../model/pullRequests.ts";
|
import type { PullRequestLine } from "../model/pullRequests.ts";
|
||||||
import { Button, isLeftClick, isRightClick, useHover } from "./Button.tsx";
|
import { Button, isLeftClick, isRightClick, useHover } from "./Button.tsx";
|
||||||
import { colors } from "./theme.ts";
|
import { colors, type Palette } from "./theme.ts";
|
||||||
|
|
||||||
export interface PullRequestViewState {
|
export interface PullRequestViewState {
|
||||||
readonly status: "loading" | "ready" | "error";
|
readonly status: "loading" | "ready" | "error";
|
||||||
@@ -12,15 +12,15 @@ export interface PullRequestViewState {
|
|||||||
readonly error?: string;
|
readonly error?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const LINE_COLORS: Record<PullRequestLine["kind"], string> = {
|
const LINE_COLORS: Record<PullRequestLine["kind"], keyof Palette> = {
|
||||||
title: colors.accent,
|
title: "accent",
|
||||||
meta: colors.muted,
|
meta: "muted",
|
||||||
body: colors.text,
|
body: "text",
|
||||||
check: colors.text,
|
check: "text",
|
||||||
review: colors.text,
|
review: "text",
|
||||||
comment: colors.muted,
|
comment: "muted",
|
||||||
guide: colors.text,
|
guide: "text",
|
||||||
faint: colors.faint,
|
faint: "faint",
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A linked pull request in place of the conversation: j/k scroll, o opens it, esc closes. */
|
/** 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}>
|
<scrollbox ref={props.scrollRef} flexGrow={1} minHeight={0}>
|
||||||
{view.lines.map((line, index) =>
|
{view.lines.map((line, index) =>
|
||||||
line.kind === "title" && index > 0 ? (
|
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>
|
<strong>{line.text}</strong>
|
||||||
</text>
|
</text>
|
||||||
) : line.kind === "title" ? (
|
) : line.kind === "title" ? (
|
||||||
@@ -54,7 +54,7 @@ export function PullRequestView(props: { readonly view: PullRequestViewState; re
|
|||||||
) : /^https?:\/\//.test(line.text) ? (
|
) : /^https?:\/\//.test(line.text) ? (
|
||||||
<Link key={index} text={line.text} onPress={props.onOpenUrl} />
|
<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 || " "}
|
{line.text || " "}
|
||||||
</text>
|
</text>
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export function ThreadList(props: {
|
|||||||
<box flexDirection="row">
|
<box flexDirection="row">
|
||||||
<text fg={colors.faint}>{left}</text>
|
<text fg={colors.faint}>{left}</text>
|
||||||
<box flexGrow={1} />
|
<box flexGrow={1} />
|
||||||
<text fg={status ? statusColor[status.tone] : colors.faint}>{right}</text>
|
<text fg={status ? statusColor(status.tone) : colors.faint}>{right}</text>
|
||||||
</box>
|
</box>
|
||||||
<text fg={recede ? colors.muted : colors.text}>{attention ? <strong>{title}</strong> : title}</text>
|
<text fg={recede ? colors.muted : colors.text}>{attention ? <strong>{title}</strong> : title}</text>
|
||||||
</ClickRow>,
|
</ClickRow>,
|
||||||
|
|||||||
@@ -302,9 +302,9 @@ function EventRow({ item, pending, onRespond }: { readonly onRespond: (decision:
|
|||||||
if (!block) return null;
|
if (!block) return null;
|
||||||
switch (block.kind) {
|
switch (block.kind) {
|
||||||
case "notice":
|
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":
|
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":
|
case "approval":
|
||||||
return <text marginTop={1} fg={colors.muted}>{`Approval requested: ${block.title}`}</text>;
|
return <text marginTop={1} fg={colors.muted}>{`Approval requested: ${block.title}`}</text>;
|
||||||
case "question":
|
case "question":
|
||||||
|
|||||||
+44
-17
@@ -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 { StatusTone } from "../model/threads.ts";
|
||||||
import type { Tone } from "../model/transcript.ts";
|
import type { Tone } from "../model/transcript.ts";
|
||||||
|
|
||||||
export const colors = {
|
/** Tokyo Night. */
|
||||||
|
const DARK = {
|
||||||
bg: "#16161e",
|
bg: "#16161e",
|
||||||
panel: "#1a1b26",
|
panel: "#1a1b26",
|
||||||
border: "#2f334d",
|
border: "#2f334d",
|
||||||
@@ -25,25 +26,51 @@ export const colors = {
|
|||||||
info: "#7dcfff",
|
info: "#7dcfff",
|
||||||
input: "#bb9af7",
|
input: "#bb9af7",
|
||||||
plan: "#c099ff",
|
plan: "#c099ff",
|
||||||
} as const;
|
diffAddedBg: "#1e2a1e",
|
||||||
|
diffRemovedBg: "#2d1f24",
|
||||||
export const statusColor: Record<StatusTone, string> = {
|
|
||||||
info: colors.info,
|
|
||||||
muted: colors.muted,
|
|
||||||
warn: colors.warn,
|
|
||||||
input: colors.input,
|
|
||||||
bad: colors.bad,
|
|
||||||
good: colors.good,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const toneColor: Record<Tone, string> = {
|
export type Palette = { readonly [K in keyof typeof DARK]: string };
|
||||||
normal: colors.text,
|
|
||||||
muted: colors.muted,
|
/** Tokyo Night Day, for terminals with a light background. */
|
||||||
good: colors.good,
|
const LIGHT: Palette = {
|
||||||
bad: colors.bad,
|
bg: "#e1e2e7",
|
||||||
warn: colors.warn,
|
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;
|
let markdownStyle: SyntaxStyle | undefined;
|
||||||
|
|
||||||
/** Created lazily: SyntaxStyle needs the native renderer library loaded. */
|
/** Created lazily: SyntaxStyle needs the native renderer library loaded. */
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ describe("config", () => {
|
|||||||
|
|
||||||
test("labels settings for the settings view", () => {
|
test("labels settings for the settings view", () => {
|
||||||
const rows = settingRows({ ...DEFAULT_CONFIG, followUpBehavior: "queue" });
|
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");
|
expect(rows[0]?.value).toBe("queues");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -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);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user