summaryrefslogtreecommitdiff
path: root/core/theme_schema.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/theme_schema.zig')
-rw-r--r--core/theme_schema.zig284
1 files changed, 284 insertions, 0 deletions
diff --git a/core/theme_schema.zig b/core/theme_schema.zig
new file mode 100644
index 00000000..788cf3bf
--- /dev/null
+++ b/core/theme_schema.zig
@@ -0,0 +1,284 @@
+//! What a theme says (DESIGN.md B2, B3: the themes programme's v2 schema),
+//! and the shape every theme had before it (`LegacyTheme`), with the
+//! mechanical map between the two: the theme files in core/themes and the
+//! generated ones are written in the old names until their own lines move
+//! them, and a ThemeFile written in them (a user's own, DumpThemes' output
+//! of an older build) loads forever. colors.zig derives everything a
+//! surface draws from a `Theme` (colors.Chrome.of).
+const std = @import("std");
+
+/// A theme: ten colours, the syntax four among them, and the terminal's
+/// sixteen (B2), each named for its role; then what a faithful port, acme
+/// or lapis says of its own where the derived one would not be its (B3),
+/// each derived when absent (colors.Chrome.of, rule by rule).
+pub const Theme = struct {
+ name: []const u8,
+ /// The body's ground and ink; null leaves them to the host terminal (a
+ /// window: colors.null_page and #cccccc).
+ page: ?[3]u8,
+ text: ?[3]u8,
+ /// A pane's tag at rest, and its ink.
+ tag: [3]u8,
+ tag_text: [3]u8,
+ /// The theme's one accent: the focused grip, keys, the walked word,
+ /// links, the sam fence.
+ accent: [3]u8,
+ /// The selection's ground (its ink is derived, or `selection_text`).
+ selection: [3]u8,
+ keyword: [3]u8,
+ string: [3]u8,
+ number: [3]u8,
+ comment: [3]u8,
+ /// The terminal's sixteen, and the semantic hues: 1 red (error,
+ /// deleted), 2 green (added), 3 yellow (warning, hits), 4 blue (info), 6
+ /// cyan (hint). Null: derived from the theme's own hues (R14).
+ ansi: ?[16][3]u8,
+
+ // The overrides (B3).
+ selection_text: ?[3]u8 = null,
+ /// The focused tag's ground and ink (R4: else the tag a focus step off).
+ tag_focus: ?[3]u8 = null,
+ tag_focus_text: ?[3]u8 = null,
+ /// The mark on a reading pane's grip (R5', DESIGN.md G1': else sky,
+ /// mint, violet, paper or rose, the first told from the grip's other
+ /// hues, 3:1 on the tags).
+ mode: ?[3]u8 = null,
+ /// A name's tint in a tag (R13: else a hue of the theme's own at the
+ /// tag ink's lightness).
+ tag_name: ?[3]u8 = null,
+ /// The workspace row, an editor's status bar where it has one.
+ workspace: ?[3]u8 = null,
+ workspace_text: ?[3]u8 = null,
+ line_number: ?[3]u8 = null,
+ line_number_current: ?[3]u8 = null,
+ /// A search hit's ground (R8: else the page toward amber).
+ hit: ?[3]u8 = null,
+ /// The severities' inks (R9: else the ANSI red, yellow, blue, cyan).
+ @"error": ?[3]u8 = null,
+ warning: ?[3]u8 = null,
+ info: ?[3]u8 = null,
+ hint: ?[3]u8 = null,
+ /// What a diff adds and deletes (R10: else ANSI 2 and 1).
+ added: ?[3]u8 = null,
+ deleted: ?[3]u8 = null,
+ /// The rules between panes and columns, the scroll column and its
+ /// thumb, what an empty column shows, the rule under a tag (R11).
+ rule: ?[3]u8 = null,
+ rail: ?[3]u8 = null,
+ rail_thumb: ?[3]u8 = null,
+ empty_column: ?[3]u8 = null,
+ tag_rule: ?[3]u8 = null,
+ /// A grip's ring at rest, its fill while its file is unsaved, and a
+ /// column's grip (R6).
+ grip_ring: ?[3]u8 = null,
+ dirty: ?[3]u8 = null,
+ column_grip: ?[3]u8 = null,
+ /// A tag's selection where it is not the body's (acme's #9eeeee), and
+ /// each pointer button's sweep, select, exec and look (R7).
+ tag_selection: ?[3]u8 = null,
+ sweeps: ?[3]Sweep = null,
+ /// A pixel shell's rules and scroll column, in pixels (2 and 12 unset).
+ rule_px: ?u8 = null,
+ rail_px: ?u8 = null,
+
+ pub const Sweep = struct { ground: [3]u8, text: [3]u8 };
+
+ /// A theme in the old names, in the new: each field renamed, the ones
+ /// now always derived (`dropped`) left out, the sweeps' two lists one.
+ pub fn fromLegacy(old: LegacyTheme) Theme {
+ var out: Theme = undefined;
+ inline for (renames) |r| @field(out, r[1]) = @field(old, r[0]);
+ out.sweeps = if (old.sweep_bg) |grounds| sweeps: {
+ var s: [3]Sweep = undefined;
+ for (&s, grounds, 0..) |*sweep, ground, i| sweep.* = .{ .ground = ground, .text = if (old.sweep_fg) |inks| inks[i] else old.sel_fg };
+ break :sweeps s;
+ } else null;
+ out.mode = null;
+ out.added = null;
+ out.deleted = null;
+ return out;
+ }
+
+ /// The old names' view of a theme, for what still reads them: the
+ /// fields the new names leave to the derivation (`derived`) filled in
+ /// from it; `added`, `deleted` and `mode`, which the old names have no
+ /// field for, left out.
+ pub fn toLegacy(th: *const Theme, derived: Derived) LegacyTheme {
+ var out: LegacyTheme = undefined;
+ inline for (renames) |r| {
+ const from = @field(th, r[1]);
+ const same = comptime @FieldType(LegacyTheme, r[0]) == @TypeOf(from);
+ @field(out, r[0]) = if (same) from else from orelse @field(derived, r[0]);
+ }
+ inline for (dropped) |name| @field(out, name) = @field(derived, name);
+ if (th.sweeps) |sweeps| {
+ out.sweep_bg = undefined;
+ out.sweep_fg = undefined;
+ for (sweeps, &out.sweep_bg.?, &out.sweep_fg.?) |s, *ground, *ink| {
+ ground.* = s.ground;
+ ink.* = s.text;
+ }
+ } else {
+ out.sweep_bg = null;
+ out.sweep_fg = null;
+ }
+ return out;
+ }
+
+ /// What `toLegacy` takes from the derivation: the old names' required
+ /// fields the new ones make optional, and the ones they leave out.
+ pub const Derived = struct {
+ sel_fg: [3]u8,
+ lineno: [3]u8,
+ scroll_track: [3]u8,
+ scroll_thumb: [3]u8,
+ box_dim: [3]u8,
+ column_box_dim: ?[3]u8 = null,
+ tag_active_name_fg: ?[3]u8 = null,
+ search_fg: ?[3]u8 = null,
+ tag_reading_bg: ?[3]u8 = null,
+ };
+};
+
+/// Old name, new name: the mechanical layer (DESIGN.md G6). Without the
+/// rename this table, `LegacyTheme` and the two maps go.
+const renames = [_][2][]const u8{
+ .{ "name", "name" },
+ .{ "bg", "page" },
+ .{ "fg", "text" },
+ .{ "tag_bg", "tag" },
+ .{ "tag_fg", "tag_text" },
+ .{ "box", "accent" },
+ .{ "sel_bg", "selection" },
+ .{ "kw", "keyword" },
+ .{ "str", "string" },
+ .{ "num", "number" },
+ .{ "comment", "comment" },
+ .{ "palette", "ansi" },
+ .{ "sel_fg", "selection_text" },
+ .{ "tag_active_bg", "tag_focus" },
+ .{ "tag_active_fg", "tag_focus_text" },
+ .{ "tag_name_fg", "tag_name" },
+ .{ "tagline_bg", "workspace" },
+ .{ "tagline_fg", "workspace_text" },
+ .{ "lineno", "line_number" },
+ .{ "lineno_active", "line_number_current" },
+ .{ "search_bg", "hit" },
+ .{ "diagnostic_error", "error" },
+ .{ "diagnostic_warning", "warning" },
+ .{ "diagnostic_info", "info" },
+ .{ "diagnostic_hint", "hint" },
+ .{ "border", "rule" },
+ .{ "scroll_track", "rail" },
+ .{ "scroll_thumb", "rail_thumb" },
+ .{ "empty_col", "empty_column" },
+ .{ "tag_rule", "tag_rule" },
+ .{ "box_border", "grip_ring" },
+ .{ "box_dirty", "dirty" },
+ .{ "column_box", "column_grip" },
+ .{ "tag_sel_bg", "tag_selection" },
+ .{ "rule_px", "rule_px" },
+ .{ "rail_px", "rail_px" },
+};
+
+/// The old fields the new names derive always (B8), and the reading tag's
+/// ground, which is the tag's now (G1').
+const dropped = [_][]const u8{ "box_dim", "column_box_dim", "tag_active_name_fg", "search_fg", "tag_reading_bg" };
+
+// Every old field is renamed, dropped, or a sweep's; every new one renamed
+// to, the sweeps, or new (`mode`, `added`, `deleted`): a field added to either
+// without its line here is a compile error.
+comptime {
+ @setEvalBranchQuota(20_000);
+ for (@typeInfo(LegacyTheme).@"struct".field_names) |f| {
+ const known = for (renames) |r| {
+ if (std.mem.eql(u8, r[0], f)) break true;
+ } else for (dropped) |d| {
+ if (std.mem.eql(u8, d, f)) break true;
+ } else std.mem.eql(u8, f, "sweep_bg") or std.mem.eql(u8, f, "sweep_fg");
+ if (!known) @compileError("LegacyTheme." ++ f ++ " has no new name");
+ }
+ for (@typeInfo(Theme).@"struct".field_names) |f| {
+ const known = for (renames) |r| {
+ if (std.mem.eql(u8, r[1], f)) break true;
+ } else std.mem.eql(u8, f, "sweeps") or std.mem.eql(u8, f, "mode") or std.mem.eql(u8, f, "added") or std.mem.eql(u8, f, "deleted");
+ if (!known) @compileError("Theme." ++ f ++ " has no old name");
+ }
+}
+
+/// A theme as every theme was written up to 2026-11-25: the files in
+/// core/themes and the generated ones (folded through it at comptime:
+/// colors.fold), and every ThemeFile in it (`.tag_bg` names it).
+pub const LegacyTheme = struct {
+ name: []const u8,
+ bg: ?[3]u8,
+ fg: ?[3]u8,
+ sel_bg: [3]u8,
+ sel_fg: [3]u8,
+ tag_bg: [3]u8,
+ tag_fg: [3]u8,
+ box: [3]u8, // move box, focused pane
+ box_dim: [3]u8, // move box, everything else
+ kw: [3]u8,
+ str: [3]u8,
+ num: [3]u8,
+ comment: [3]u8,
+ lineno: [3]u8,
+ scroll_track: [3]u8,
+ scroll_thumb: [3]u8,
+ palette: ?[16][3]u8,
+
+ // Pardes UI roles. Optional so existing ThemeFile documents and imported
+ // editor palettes keep working; ChromeTheme resolves their legacy defaults.
+ tag_active_bg: ?[3]u8 = null,
+ tag_active_fg: ?[3]u8 = null,
+ /// The workspace row (the tagline): an editor's status bar in its own
+ /// colours, where it has them; else the tag's.
+ tagline_bg: ?[3]u8 = null,
+ tagline_fg: ?[3]u8 = null,
+ /// Filename/output-name accent, also used by the Term command.
+ tag_name_fg: ?[3]u8 = null,
+ /// Active tint; absence preserves the shared name tint or active tag ink.
+ tag_active_name_fg: ?[3]u8 = null,
+ /// Column grips stay distinct from pane grips in both focus states.
+ column_box: ?[3]u8 = null,
+ column_box_dim: ?[3]u8 = null,
+ border: ?[3]u8 = null,
+ /// What an empty column shows under its tag; the border fill without it.
+ empty_col: ?[3]u8 = null,
+ search_bg: ?[3]u8 = null,
+ search_fg: ?[3]u8 = null,
+ diagnostic_error: ?[3]u8 = null,
+ diagnostic_warning: ?[3]u8 = null,
+ diagnostic_info: ?[3]u8 = null,
+ diagnostic_hint: ?[3]u8 = null,
+ // The current line number is a quiet foreground cue, not a tag-colored
+ // background block. Older themes fall back to their normal gutter ink.
+ lineno_active: ?[3]u8 = null,
+ /// A tag's selection, where it differs from the body's (acme's #9eeeee).
+ tag_sel_bg: ?[3]u8 = null,
+ /// The tag of a reading pane, one a jump steps (Trail.zig): unset, or
+ /// too near the tag to see, the tag toward paper yellow (readingOf).
+ tag_reading_bg: ?[3]u8 = null,
+ /// Each pointer button's sweep, select, exec and look (Mouse.Button
+ /// order), and the ink over it. Unset, tints of `sel_bg` in `sel_fg`.
+ sweep_bg: ?[3][3]u8 = null,
+ sweep_fg: ?[3][3]u8 = null,
+ /// A pixel shell's rules, in pixels (2 unset); the rule between a tag
+ /// and its body is always one.
+ rule_px: ?u8 = null,
+ /// A grip is acme's button: `box` filled when focused, else a ring of
+ /// `box_border` (unset: `box_dim`) round the tag's ground; `box_dirty`
+ /// (unset: `diagnostic_warning`, then `num`) fills it, in either ring,
+ /// while its file is unsaved.
+ box_border: ?[3]u8 = null,
+ box_dirty: ?[3]u8 = null,
+ /// The rule between a pane's tag and its body, one pixel, quieter than
+ /// the rules between panes (acme's #8888cc under its 2px black ones).
+ /// Unset, halfway between the tag's ground and the page.
+ tag_rule: ?[3]u8 = null,
+ /// A pixel shell's scroll column, the grip's button over the scrollbar,
+ /// in pixels at a 17px tagline, the thumb one narrower (acme's 12px
+ /// Scrollwid, the default).
+ rail_px: ?u8 = null,
+};