xonecas.io
79113
Ma

mini-coding-agent / commit 02d44f3

feat: new theme

xonecas2026-10-05 02d44f342d090a1a16376ad414aca7a2d694eb1d parent eccdc11

7 files changed

README.md+2−0
@@ -67,6 +67,7 @@ A full example:
6767 "provider": "opencode",
6868 "model": "deepseek-v4.1-flash",
6969 "thinkingEffort": "medium",
70+ "theme": "tokyonight",
7071 "systemPrompt": "Be terse.",
7172 "sessionsDir": "/home/me/.local/state/mini-coding-agent/sessions",
7273 "discoverAgentFiles": true,
@@ -93,6 +94,7 @@ Keys:
9394 | `provider` | unset | provider id; built-ins are `opencode` and `opencode-go`, or a `customProviders` id |
9495 | `model` | unset | model id |
9596 | `thinkingEffort` | unset | one of `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`; unset sends no reasoning parameter and clamps to what the model accepts |
97+| `theme` | `tokyonight` | TUI palette: `tokyonight` or `oxocarbon`. Read at startup; there is no live reload |
9698 | `systemPrompt` | `""` | prepended to the system prompt |
9799 | `sessionsDir` | `$XDG_STATE_HOME/mini-coding-agent/sessions`, else `$HOME/.local/state/mini-coding-agent/sessions`, else `sessions` | where JSONL session logs go |
98100 | `discoverAgentFiles` | `true` | load `AGENTS.md`/`CLAUDE.md` from `$HOME/.agents` and the cwd |
src/config.zig+9−0
@@ -6,6 +6,7 @@
66 const std = @import("std");
77 const platform = @import("platform.zig");
88 const util = @import("util.zig");
9+const theme = @import("tui/theme.zig");
910
1011 pub const ToolName = enum { edit, read, bash };
1112
@@ -32,6 +33,8 @@ pub const Config = struct {
3233 model: ?[]const u8,
3334 /// Null when unset: no reasoning parameter is sent, so the provider picks.
3435 thinking_effort: ?[]const u8,
36+ /// A theme id; see `theme.find`.
37+ theme: []const u8,
3538 custom_providers: []const CustomProvider,
3639 };
3740
@@ -41,6 +44,7 @@ const known_keys = [_][]const u8{
4144 "sessionsDir", "systemPrompt", "discoverAgentFiles",
4245 "skillsDirs", "tools", "provider",
4346 "model", "thinkingEffort", "customProviders",
47+ "theme",
4448 };
4549
4650 fn configDir(a: std.mem.Allocator) []const u8 {
@@ -223,6 +227,10 @@ fn readInto(a: std.mem.Allocator, path: []const u8, required: bool, cfg: *Config
223227 if (!ok) return fail(a, path, "unknown thinkingEffort \"{s}\"", .{v});
224228 cfg.thinking_effort = v;
225229 }
230+ if (try strField(a, obj, "theme", path)) |v| {
231+ if (theme.find(v) == null) return fail(a, path, "unknown theme \"{s}\"", .{v});
232+ cfg.theme = v;
233+ }
226234 }
227235
228236 /// The subset of config a TUI command persists. `null` leaves a key alone.
@@ -274,6 +282,7 @@ fn defaults(a: std.mem.Allocator) !Config {
274282 .provider = null,
275283 .model = null,
276284 .thinking_effort = null,
285+ .theme = theme.default_id,
277286 .custom_providers = &.{},
278287 };
279288 }
src/tui/highlight.zig+5−5
@@ -1,7 +1,7 @@
11 //! Syntax highlighting for committed scrollback, once, over the whole block.
22 //! Grammars are linked C artifacts; their `highlights.scm` queries ship with
3-//! the grammar and are consumed as data. Capture names are mapped to the
4-//! TokyoNight palette in `theme.zig`.
3+//! the grammar and are consumed as data. Capture names are mapped to the active
4+//! theme's palette in `theme.zig`.
55
66 const std = @import("std");
77 const ts = @import("tree-sitter");
@@ -336,7 +336,7 @@ pub fn highlightMarkdown(a: std.mem.Allocator, text: []const u8) []const u8 {
336336 spans.items,
337337 start + byteOf(iu, code.startByte() / 2),
338338 start + byteOf(iu, code.endByte() / 2),
339- theme.INLINE_CODE,
339+ theme.current.inline_code,
340340 ));
341341 }
342342
@@ -357,8 +357,8 @@ pub fn highlightMarkdown(a: std.mem.Allocator, text: []const u8) []const u8 {
357357 break;
358358 }
359359 }
360- const idx = @min(level, theme.HEADINGS.len) - 1;
361- spans = std.ArrayList(Span).fromOwnedSlice(recolor(a, spans.items, byteOf(u, heading.startByte() / 2), byteOf(u, heading.endByte() / 2), theme.HEADINGS[idx]));
360+ const idx = @min(level, theme.current.headings.len) - 1;
361+ spans = std.ArrayList(Span).fromOwnedSlice(recolor(a, spans.items, byteOf(u, heading.startByte() / 2), byteOf(u, heading.endByte() / 2), theme.current.headings[idx]));
362362 }
363363 return paint(a, text, spans.items);
364364 }
src/tui/stream.zig+1−1
@@ -185,7 +185,7 @@ pub const TailStream = struct {
185185 pub fn pending(self: *TailStream) []BodyLine {
186186 var out: std.ArrayList(BodyLine) = .empty;
187187 if (self.rest.items.len > 0) {
188- out.append(self.a, .{ .text = self.rest.items, .style = .{ .fg = theme.PALETTE.comment } }) catch {};
188+ out.append(self.a, .{ .text = self.rest.items, .style = .{ .fg = theme.current.comment } }) catch {};
189189 }
190190 return out.items;
191191 }
src/tui/styles.zig+4−4
@@ -21,15 +21,15 @@ pub fn styledWith(a: std.mem.Allocator, style: theme.Style, text: []const u8) []
2121
2222 /// `Comment`, the colour diff context lines share.
2323 pub fn dim(a: std.mem.Allocator, text: []const u8) []const u8 {
24- return fg(a, theme.PALETTE.comment, text);
24+ return fg(a, theme.current.comment, text);
2525 }
2626 pub fn red(a: std.mem.Allocator, text: []const u8) []const u8 {
27- return fg(a, theme.PALETTE.red, text);
27+ return fg(a, theme.current.error_, text);
2828 }
2929 pub fn yellow(a: std.mem.Allocator, text: []const u8) []const u8 {
30- return fg(a, theme.PALETTE.yellow, text);
30+ return fg(a, theme.current.warn, text);
3131 }
3232 /// The tool accent: call-line heads.
3333 pub fn teal(a: std.mem.Allocator, text: []const u8) []const u8 {
34- return fg(a, theme.PALETTE.teal, text);
34+ return fg(a, theme.current.accent, text);
3535 }
src/tui/theme.zig+221−121
@@ -1,35 +1,228 @@
1-//! The one palette: the TokyoNight `night` slots the TUI uses. Every colour the
2-//! TUI writes comes from here, foreground and background alike, so no row can
3-//! fall back to the terminal's own colours. Truecolor only.
1+//! The palettes: one per theme id. Every colour the TUI writes comes from the
2+//! active theme, foreground and background alike, so no row can fall back to
3+//! the terminal's own colours. Truecolor only.
4+//!
5+//! A theme is one `Theme` value: the slots the TUI itself paints with, then its
6+//! own capture table and its own heading ramp. The capture tables are not
7+//! shared, so a theme maps a capture the way its own upstream theme does.
8+//!
9+//! The theme is chosen once at startup and never changes: `init` runs before the
10+//! first row is painted, and nothing writes `current` again.
411
512 const std = @import("std");
613
7-pub const PALETTE = struct {
8- pub const bg = "#1a1b26";
9- pub const fg = "#c0caf5";
10- pub const fg_dark = "#a9b1d6";
11- pub const comment = "#565f89";
12- pub const terminal_black = "#414868";
13- pub const blue = "#7aa2f7";
14- pub const blue1 = "#2ac3de";
15- pub const blue5 = "#89ddff";
16- pub const green = "#9ece6a";
17- pub const green1 = "#73daca";
18- pub const magenta = "#bb9af7";
19- pub const orange = "#ff9e64";
20- pub const purple = "#9d7cd8";
21- pub const red = "#f7768e";
22- pub const teal = "#1abc9c";
23- pub const yellow = "#e0af68";
14+pub const Style = struct {
15+ fg: ?[]const u8 = null,
16+ bg: ?[]const u8 = null,
17+ bold: bool = false,
18+ italic: bool = false,
19+ underline: bool = false,
20+};
21+
22+/// One capture table entry. A dotted name falls back to its parent.
23+const Capture = struct { name: []const u8, style: Style };
24+
25+pub const Theme = struct {
26+ /// `Normal`: the pair every row is painted with, and restored to.
27+ fg: []const u8,
28+ bg: []const u8,
29+ /// `Comment`: diff context, the status row, the elision notes.
30+ comment: []const u8,
31+ /// The user's own text, a diff path and hunk header, command output.
32+ prompt: []const u8,
33+ /// The tool accent: call-line heads.
34+ accent: []const u8,
35+ /// Diff `+` lines.
36+ add: []const u8,
37+ /// Diff `-` lines, and every error.
38+ error_: []const u8,
39+ /// A near-full context window.
40+ warn: []const u8,
41+ /// Diff row backgrounds.
42+ diff_add: []const u8,
43+ diff_delete: []const u8,
44+ /// Inline code, `@markup.raw.markdown_inline`.
45+ inline_code: Style,
46+ /// One style per Markdown heading level; the last covers every deeper level.
47+ headings: []const Style,
48+ captures: []const Capture,
49+};
50+
51+// ---- TokyoNight `night` ---------------------------------------------------
52+
53+const TOKYONIGHT = Theme{
54+ .fg = "#c0caf5",
55+ .bg = "#1a1b26",
56+ .comment = "#565f89",
57+ .prompt = "#7aa2f7",
58+ .accent = "#1abc9c",
59+ .add = "#9ece6a",
60+ .error_ = "#f7768e",
61+ .warn = "#e0af68",
62+ .diff_add = "#243e4a",
63+ .diff_delete = "#4a272f",
64+ .inline_code = .{ .fg = "#7aa2f7", .bg = "#414868" },
65+ .headings = &TOKYONIGHT_HEADINGS,
66+ .captures = &TOKYONIGHT_CAPTURES,
2467 };
2568
26-/// `Normal`: the pair every row is painted with, and restored to.
27-pub const NORMAL_FG = PALETTE.fg;
28-pub const NORMAL_BG = PALETTE.bg;
69+/// Headings take their level's colour from TokyoNight's rainbow over a tint.
70+const TOKYONIGHT_HEADINGS = [_]Style{
71+ .{ .fg = "#7aa2f7", .bg = "#24293b", .bold = true },
72+ .{ .fg = "#e0af68", .bg = "#2e2a2d", .bold = true },
73+ .{ .fg = "#9ece6a", .bg = "#272d2d", .bold = true },
74+ .{ .fg = "#1abc9c", .bg = "#1a2b32", .bold = true },
75+ .{ .fg = "#bb9af7", .bg = "#2a283b", .bold = true },
76+ .{ .fg = "#9d7cd8", .bg = "#272538", .bold = true },
77+ .{ .fg = "#ff9e64", .bg = "#31282c", .bold = true },
78+ .{ .fg = "#f7768e", .bg = "#302430", .bold = true },
79+};
80+
81+const TOKYONIGHT_CAPTURES = [_]Capture{
82+ .{ .name = "boolean", .style = .{ .fg = "#ff9e64" } },
83+ .{ .name = "character", .style = .{ .fg = "#9ece6a" } },
84+ .{ .name = "comment", .style = .{ .fg = "#565f89" } },
85+ .{ .name = "constant", .style = .{ .fg = "#ff9e64" } },
86+ .{ .name = "constant.builtin", .style = .{ .fg = "#2ac3de" } },
87+ .{ .name = "constructor", .style = .{ .fg = "#bb9af7" } },
88+ .{ .name = "escape", .style = .{ .fg = "#bb9af7" } },
89+ .{ .name = "function", .style = .{ .fg = "#7aa2f7" } },
90+ .{ .name = "function.builtin", .style = .{ .fg = "#2ac3de" } },
91+ .{ .name = "keyword", .style = .{ .fg = "#9d7cd8" } },
92+ .{ .name = "label", .style = .{ .fg = "#7aa2f7" } },
93+ // `@module` is TokyoNight's `Include`, which is undefined there and falls
94+ // through to `PreProc`, a cyan the palette does not carry.
95+ .{ .name = "module", .style = .{ .fg = "#2ac3de" } },
96+ .{ .name = "number", .style = .{ .fg = "#ff9e64" } },
97+ .{ .name = "operator", .style = .{ .fg = "#89ddff" } },
98+ .{ .name = "property", .style = .{ .fg = "#73daca" } },
99+ .{ .name = "punctuation.bracket", .style = .{ .fg = "#a9b1d6" } },
100+ .{ .name = "punctuation.delimiter", .style = .{ .fg = "#89ddff" } },
101+ .{ .name = "punctuation.special", .style = .{ .fg = "#89ddff" } },
102+ .{ .name = "string", .style = .{ .fg = "#9ece6a" } },
103+ .{ .name = "string.special", .style = .{ .fg = "#2ac3de" } },
104+ .{ .name = "type", .style = .{ .fg = "#2ac3de" } },
105+ .{ .name = "type.builtin", .style = .{ .fg = "#27a1b9" } },
106+ .{ .name = "variable", .style = .{ .fg = "#c0caf5" } },
107+ .{ .name = "variable.builtin", .style = .{ .fg = "#f7768e" } },
108+ .{ .name = "variable.parameter", .style = .{ .fg = "#e0af68" } },
109+ // Markdown's queries predate the `@markup` rename; these are the old names.
110+ .{ .name = "text.emphasis", .style = .{ .italic = true } },
111+ .{ .name = "text.strong", .style = .{ .bold = true } },
112+ .{ .name = "text.literal", .style = .{ .fg = "#9ece6a" } },
113+ .{ .name = "text.title", .style = .{ .fg = "#7aa2f7", .bold = true } },
114+ .{ .name = "text.uri", .style = .{ .underline = true } },
115+ .{ .name = "text.reference", .style = .{ .fg = "#2ac3de" } },
116+};
29117
30-/// Diff row backgrounds, from the `DiffAdd`/`DiffDelete` groups.
31-pub const DIFF_ADD = "#243e4a";
32-pub const DIFF_DELETE = "#4a272f";
118+// ---- Oxocarbon ------------------------------------------------------------
119+
120+/// The greys are the upstream `blend_hex(base00, base06, n)` ramp resolved to
121+/// hex. The two diff tints are the upstream `DiffAdd` and `DiffDelete`.
122+const OXOCARBON = Theme{
123+ .fg = "#d0d0d0",
124+ .bg = "#161616",
125+ .comment = "#525252",
126+ .prompt = "#78a9ff",
127+ .accent = "#3ddbd9",
128+ .add = "#08bdba",
129+ .error_ = "#ee5396",
130+ .warn = "#be95ff",
131+ .diff_add = "#122f2f",
132+ .diff_delete = "#361c28",
133+ .inline_code = .{ .fg = "#be95ff", .bg = "#262626" },
134+ .headings = &OXOCARBON_HEADINGS,
135+ .captures = &OXOCARBON_CAPTURES,
136+};
137+
138+/// Oxocarbon paints every heading level with one colour, `markdownH1` = base10,
139+/// so the ramp is a single entry and the clamp sends every level to it.
140+const OXOCARBON_HEADINGS = [_]Style{
141+ .{ .fg = "#ee5396", .bg = "#2c1c23", .bold = true },
142+};
143+
144+const OXOCARBON_CAPTURES = [_]Capture{
145+ .{ .name = "boolean", .style = .{ .fg = "#78a9ff" } },
146+ .{ .name = "character", .style = .{ .fg = "#be95ff" } },
147+ .{ .name = "comment", .style = .{ .fg = "#525252", .italic = true } },
148+ .{ .name = "constant", .style = .{ .fg = "#be95ff" } },
149+ .{ .name = "constant.builtin", .style = .{ .fg = "#08bdba" } },
150+ .{ .name = "constructor", .style = .{ .fg = "#78a9ff" } },
151+ .{ .name = "function", .style = .{ .fg = "#ff7eb6", .bold = true } },
152+ .{ .name = "function.builtin", .style = .{ .fg = "#ff7eb6" } },
153+ .{ .name = "keyword", .style = .{ .fg = "#78a9ff" } },
154+ .{ .name = "label", .style = .{ .fg = "#82cfff" } },
155+ // `@module` is `Include` upstream, base09.
156+ .{ .name = "module", .style = .{ .fg = "#78a9ff" } },
157+ .{ .name = "number", .style = .{ .fg = "#82cfff" } },
158+ .{ .name = "operator", .style = .{ .fg = "#78a9ff" } },
159+ .{ .name = "property", .style = .{ .fg = "#ee5396" } },
160+ .{ .name = "punctuation.bracket", .style = .{ .fg = "#3ddbd9" } },
161+ .{ .name = "punctuation.delimiter", .style = .{ .fg = "#3ddbd9" } },
162+ .{ .name = "punctuation.special", .style = .{ .fg = "#3ddbd9" } },
163+ .{ .name = "string", .style = .{ .fg = "#be95ff" } },
164+ .{ .name = "string.special", .style = .{ .fg = "#be95ff" } },
165+ .{ .name = "type", .style = .{ .fg = "#78a9ff" } },
166+ .{ .name = "type.builtin", .style = .{ .fg = "#78a9ff" } },
167+ .{ .name = "variable", .style = .{ .fg = "#d0d0d0" } },
168+ .{ .name = "variable.builtin", .style = .{ .fg = "#d0d0d0" } },
169+ .{ .name = "variable.parameter", .style = .{ .fg = "#d0d0d0" } },
170+ .{ .name = "text.emphasis", .style = .{ .fg = "#ee5396", .bold = true } },
171+ .{ .name = "text.strong", .style = .{ .bold = true } },
172+ .{ .name = "text.literal", .style = .{ .fg = "#d0d0d0" } },
173+ .{ .name = "text.title", .style = .{ .fg = "#ee5396" } },
174+ .{ .name = "text.uri", .style = .{ .fg = "#be95ff", .underline = true } },
175+ .{ .name = "text.reference", .style = .{ .fg = "#d0d0d0" } },
176+};
177+
178+// ---- the active theme -----------------------------------------------------
179+
180+/// The id a config with no `theme` key gets.
181+pub const default_id = "tokyonight";
182+
183+/// The theme `id` names, or null when no theme does.
184+pub fn find(id: []const u8) ?*const Theme {
185+ if (std.mem.eql(u8, id, "tokyonight")) return &TOKYONIGHT;
186+ if (std.mem.eql(u8, id, "oxocarbon")) return &OXOCARBON;
187+ return null;
188+}
189+
190+/// The active theme. Set once by `init`; every call site reads it.
191+pub var current: *const Theme = &TOKYONIGHT;
192+
193+/// The three sequences a row starts and ends in, built from the active theme.
194+/// Comptime while the palette was fixed; runtime now, because the palette is
195+/// not known until the config is read.
196+pub var SGR_PLAIN: []const u8 = "";
197+pub var SGR_NORMAL_FG: []const u8 = "";
198+pub var SGR_NORMAL_BG: []const u8 = "";
199+
200+/// Selects the theme and bakes its sequences. Runs once, before the first row
201+/// is painted. An unknown id falls back to the default.
202+pub fn init(a: std.mem.Allocator, id: []const u8) void {
203+ current = find(id) orelse &TOKYONIGHT;
204+ const f = rgb(current.fg);
205+ const b = rgb(current.bg);
206+ SGR_PLAIN = std.fmt.allocPrint(a, "\x1b[22;23;24;38;2;{d};{d};{d};48;2;{d};{d};{d}m", .{
207+ f[0], f[1], f[2], b[0], b[1], b[2],
208+ }) catch "";
209+ SGR_NORMAL_FG = sgrFg(a, current.fg);
210+ SGR_NORMAL_BG = sgrBg(a, current.bg);
211+}
212+
213+/// A capture's style, falling back to its dotted parent; null when unmapped.
214+pub fn styleFor(capture: []const u8) ?Style {
215+ var name = capture;
216+ while (true) {
217+ for (current.captures) |entry| {
218+ if (std.mem.eql(u8, entry.name, name)) return entry.style;
219+ }
220+ const dot = std.mem.lastIndexOfScalar(u8, name, '.') orelse return null;
221+ name = name[0..dot];
222+ }
223+}
224+
225+// ---- colour helpers -------------------------------------------------------
33226
34227 /// The three channels of one `#rrggbb`.
35228 fn rgb(hex: []const u8) [3]u8 {
@@ -40,12 +233,6 @@ fn rgb(hex: []const u8) [3]u8 {
40233 };
41234 }
42235
43-/// A compile-time SGR sequence for one fixed `#rrggbb`.
44-fn sgrConst(comptime code: []const u8, comptime hex: []const u8) []const u8 {
45- const c = comptime rgb(hex);
46- return std.fmt.comptimePrint("\x1b[{s}{d};{d};{d}m", .{ code, c[0], c[1], c[2] });
47-}
48-
49236 /// Explicit colour, never a reset: a `39`/`49` or a `0` would hand the rest of
50237 /// the row back to the host terminal, which is the leak this palette closes.
51238 pub fn sgrFg(a: std.mem.Allocator, hex: []const u8) []const u8 {
@@ -58,33 +245,12 @@ pub fn sgrBg(a: std.mem.Allocator, hex: []const u8) []const u8 {
58245 return std.fmt.allocPrint(a, "\x1b[48;2;{d};{d};{d}m", .{ c[0], c[1], c[2] }) catch "";
59246 }
60247
61-/// Attributes off, then `Normal`. The state a row starts and ends in.
62-pub const SGR_PLAIN = blk: {
63- const f = rgb(NORMAL_FG);
64- const b = rgb(NORMAL_BG);
65- break :blk std.fmt.comptimePrint("\x1b[22;23;24;38;2;{d};{d};{d};48;2;{d};{d};{d}m", .{ f[0], f[1], f[2], b[0], b[1], b[2] });
66-};
67-
68-/// `Normal`'s foreground, restored after a span so no cell inherits a colour.
69-pub const SGR_NORMAL_FG = sgrConst("38;2;", NORMAL_FG);
70-
71-/// `Normal`'s row background, the tint every plain row is painted with.
72-pub const SGR_NORMAL_BG = sgrConst("48;2;", NORMAL_BG);
73-
74-pub const Style = struct {
75- fg: ?[]const u8 = null,
76- bg: ?[]const u8 = null,
77- bold: bool = false,
78- italic: bool = false,
79- underline: bool = false,
80-};
81-
82248 /// A style's own attributes, with the defaults spelled out: a span that names
83249 /// no colour must not inherit the colour of the span or token before it, and
84250 /// the fallback is the palette's `Normal`, never the terminal's own pair.
85251 pub fn sgr(a: std.mem.Allocator, style: Style) []const u8 {
86- const f = rgb(style.fg orelse NORMAL_FG);
87- const b = rgb(style.bg orelse NORMAL_BG);
252+ const f = rgb(style.fg orelse current.fg);
253+ const b = rgb(style.bg orelse current.bg);
88254 return std.fmt.allocPrint(a, "\x1b[{s}{s}{s}38;2;{d};{d};{d};48;2;{d};{d};{d}m", .{
89255 if (style.bold) "1;" else "",
90256 if (style.italic) "3;" else "",
@@ -97,69 +263,3 @@ pub fn sgr(a: std.mem.Allocator, style: Style) []const u8 {
97263 b[2],
98264 }) catch "";
99265 }
100-
101-/// Capture name to colour, mapped the way `folke/tokyonight.nvim` maps capture
102-/// names to highlight groups. A dotted name falls back to its parent.
103-const STYLES = [_]struct { name: []const u8, style: Style }{
104- .{ .name = "boolean", .style = .{ .fg = PALETTE.orange } },
105- .{ .name = "character", .style = .{ .fg = PALETTE.green } },
106- .{ .name = "comment", .style = .{ .fg = PALETTE.comment } },
107- .{ .name = "constant", .style = .{ .fg = PALETTE.orange } },
108- .{ .name = "constant.builtin", .style = .{ .fg = PALETTE.blue1 } },
109- .{ .name = "constructor", .style = .{ .fg = PALETTE.magenta } },
110- .{ .name = "escape", .style = .{ .fg = PALETTE.magenta } },
111- .{ .name = "function", .style = .{ .fg = PALETTE.blue } },
112- .{ .name = "function.builtin", .style = .{ .fg = PALETTE.blue1 } },
113- .{ .name = "keyword", .style = .{ .fg = PALETTE.purple } },
114- .{ .name = "label", .style = .{ .fg = PALETTE.blue } },
115- // `@module` is TokyoNight's `Include`, which is undefined there and falls
116- // through to `PreProc`, a cyan the palette does not carry.
117- .{ .name = "module", .style = .{ .fg = PALETTE.blue1 } },
118- .{ .name = "number", .style = .{ .fg = PALETTE.orange } },
119- .{ .name = "operator", .style = .{ .fg = PALETTE.blue5 } },
120- .{ .name = "property", .style = .{ .fg = PALETTE.green1 } },
121- .{ .name = "punctuation.bracket", .style = .{ .fg = PALETTE.fg_dark } },
122- .{ .name = "punctuation.delimiter", .style = .{ .fg = PALETTE.blue5 } },
123- .{ .name = "punctuation.special", .style = .{ .fg = PALETTE.blue5 } },
124- .{ .name = "string", .style = .{ .fg = PALETTE.green } },
125- .{ .name = "string.special", .style = .{ .fg = PALETTE.blue1 } },
126- .{ .name = "type", .style = .{ .fg = PALETTE.blue1 } },
127- .{ .name = "type.builtin", .style = .{ .fg = "#27a1b9" } },
128- .{ .name = "variable", .style = .{ .fg = PALETTE.fg } },
129- .{ .name = "variable.builtin", .style = .{ .fg = PALETTE.red } },
130- .{ .name = "variable.parameter", .style = .{ .fg = PALETTE.yellow } },
131- // Markdown's queries predate the `@markup` rename; these are the old names.
132- .{ .name = "text.emphasis", .style = .{ .italic = true } },
133- .{ .name = "text.strong", .style = .{ .bold = true } },
134- .{ .name = "text.literal", .style = .{ .fg = PALETTE.green } },
135- .{ .name = "text.title", .style = .{ .fg = PALETTE.blue, .bold = true } },
136- .{ .name = "text.uri", .style = .{ .underline = true } },
137- .{ .name = "text.reference", .style = .{ .fg = PALETTE.blue1 } },
138-};
139-
140-/// A capture's style, falling back to its dotted parent; null when unmapped.
141-pub fn styleFor(capture: []const u8) ?Style {
142- var name = capture;
143- while (true) {
144- for (STYLES) |entry| {
145- if (std.mem.eql(u8, entry.name, name)) return entry.style;
146- }
147- const dot = std.mem.lastIndexOfScalar(u8, name, '.') orelse return null;
148- name = name[0..dot];
149- }
150-}
151-
152-/// Headings take their level's colour from TokyoNight's rainbow over a tint.
153-pub const HEADINGS = [_]Style{
154- .{ .fg = PALETTE.blue, .bg = "#24293b", .bold = true },
155- .{ .fg = PALETTE.yellow, .bg = "#2e2a2d", .bold = true },
156- .{ .fg = PALETTE.green, .bg = "#272d2d", .bold = true },
157- .{ .fg = PALETTE.teal, .bg = "#1a2b32", .bold = true },
158- .{ .fg = PALETTE.magenta, .bg = "#2a283b", .bold = true },
159- .{ .fg = PALETTE.purple, .bg = "#272538", .bold = true },
160- .{ .fg = PALETTE.orange, .bg = "#31282c", .bold = true },
161- .{ .fg = PALETTE.red, .bg = "#302430", .bold = true },
162-};
163-
164-/// Inline code, `@markup.raw.markdown_inline`.
165-pub const INLINE_CODE = Style{ .fg = PALETTE.blue, .bg = PALETTE.terminal_black };
src/tui/tui.zig+12−9
@@ -61,7 +61,7 @@ fn styleRow(a: std.mem.Allocator, line: stream.BodyLine, width: usize) []const [
6161 // `ESC[K` erases after it.
6262 const styled = if (line.style) |s| styles.styledWith(a, .{
6363 .fg = s.fg,
64- .bg = line.bg orelse theme.NORMAL_BG,
64+ .bg = line.bg orelse theme.current.bg,
6565 .bold = s.bold,
6666 .italic = s.italic,
6767 .underline = s.underline,
@@ -140,11 +140,11 @@ fn isEditHeader(line: []const u8) bool {
140140 }
141141
142142 fn diffLine(line: []const u8) stream.BodyLine {
143- if (std.mem.startsWith(u8, line, "@@")) return .{ .text = line, .style = .{ .fg = theme.PALETTE.blue } };
144- if (std.mem.startsWith(u8, line, "+")) return .{ .text = line, .style = .{ .fg = theme.PALETTE.green }, .bg = theme.DIFF_ADD };
145- if (std.mem.startsWith(u8, line, "-")) return .{ .text = line, .style = .{ .fg = theme.PALETTE.red }, .bg = theme.DIFF_DELETE };
146- if (std.mem.startsWith(u8, line, "\\ No newline")) return .{ .text = line, .style = .{ .fg = theme.PALETTE.comment } };
147- if (std.mem.startsWith(u8, line, " ")) return .{ .text = line, .style = .{ .fg = theme.PALETTE.comment } };
143+ if (std.mem.startsWith(u8, line, "@@")) return .{ .text = line, .style = .{ .fg = theme.current.prompt } };
144+ if (std.mem.startsWith(u8, line, "+")) return .{ .text = line, .style = .{ .fg = theme.current.add }, .bg = theme.current.diff_add };
145+ if (std.mem.startsWith(u8, line, "-")) return .{ .text = line, .style = .{ .fg = theme.current.error_ }, .bg = theme.current.diff_delete };
146+ if (std.mem.startsWith(u8, line, "\\ No newline")) return .{ .text = line, .style = .{ .fg = theme.current.comment } };
147+ if (std.mem.startsWith(u8, line, " ")) return .{ .text = line, .style = .{ .fg = theme.current.comment } };
148148 return .{ .text = line };
149149 }
150150
@@ -155,7 +155,7 @@ fn diffLine(line: []const u8) stream.BodyLine {
155155 fn diffRows(a: std.mem.Allocator, diffs: []const common.FileDiff) []const stream.BodyLine {
156156 var out: std.ArrayList(stream.BodyLine) = .empty;
157157 for (diffs) |d| {
158- out.append(a, .{ .text = d.path, .style = .{ .fg = theme.PALETTE.blue } }) catch {};
158+ out.append(a, .{ .text = d.path, .style = .{ .fg = theme.current.prompt } }) catch {};
159159 if (d.patch) |patch| {
160160 const trimmed = std.mem.trimEnd(u8, patch, " \t\r\n");
161161 var it = std.mem.splitScalar(u8, trimmed, '\n');
@@ -166,7 +166,7 @@ fn diffRows(a: std.mem.Allocator, diffs: []const common.FileDiff) []const stream
166166 out.append(a, diffLine(l)) catch {};
167167 }
168168 } else if (d.note) |note| {
169- out.append(a, .{ .text = note, .style = .{ .fg = theme.PALETTE.comment } }) catch {};
169+ out.append(a, .{ .text = note, .style = .{ .fg = theme.current.comment } }) catch {};
170170 }
171171 }
172172 return out.items;
@@ -470,7 +470,7 @@ const Tui = struct {
470470 self.separator = true;
471471 var it = std.mem.splitScalar(u8, text, '\n');
472472 var lines: std.ArrayList(stream.BodyLine) = .empty;
473- while (it.next()) |l| lines.append(self.s, .{ .text = l, .style = .{ .fg = theme.PALETTE.blue } }) catch {};
473+ while (it.next()) |l| lines.append(self.s, .{ .text = l, .style = .{ .fg = theme.current.prompt } }) catch {};
474474 self.commitLines(lines.items);
475475 self.separator = true;
476476 }
@@ -1133,6 +1133,9 @@ fn eventTrampoline(ctx: *anyopaque, event: agent.Event) void {
11331133 /// Runs the TUI until the user exits. `opts` and `cfg` outlive the call.
11341134 pub fn run(opts: agent.Options, cfg: *const config.Config, tool_names: []const config.ToolName) !void {
11351135 const gpa = platform.gpa;
1136+ // The theme is chosen once, before anything is painted: the sequences the
1137+ // rows are wrapped in are baked from it.
1138+ theme.init(gpa, cfg.theme);
11361139 const opts_ptr = try gpa.create(agent.Options);
11371140 opts_ptr.* = opts;
11381141 const self = try gpa.create(Tui);