summaryrefslogtreecommitdiff
path: root/tools/gen_themes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gen_themes.zig')
-rw-r--r--tools/gen_themes.zig146
1 files changed, 71 insertions, 75 deletions
diff --git a/tools/gen_themes.zig b/tools/gen_themes.zig
index b9a9adb0..fd152aa6 100644
--- a/tools/gen_themes.zig
+++ b/tools/gen_themes.zig
@@ -57,26 +57,25 @@ const Rgb = [3]u8;
/// code) — core/colors.zig's `fold` is what turns it into a real Theme.
const Theme = struct {
name: []const u8,
- bg: ?Rgb,
- fg: ?Rgb,
- sel_bg: Rgb,
- sel_fg: Rgb,
- tag_bg: Rgb,
- tag_fg: Rgb,
- box: Rgb,
- box_dim: Rgb,
- kw: Rgb,
- str: Rgb,
- num: Rgb,
+ page: ?Rgb,
+ text: ?Rgb,
+ selection: Rgb,
+ selection_text: Rgb,
+ tag: Rgb,
+ tag_text: Rgb,
+ accent: Rgb,
+ keyword: Rgb,
+ string: Rgb,
+ number: Rgb,
comment: Rgb,
- lineno: Rgb,
- scroll_track: Rgb,
- scroll_thumb: Rgb,
- /// A message's error ink (colors.Roles.err): diagnostic.error's, else
- /// error's, else the theme's red (UX E3: neonotte's diagnostic.error is
- /// an underline only).
- diagnostic_error: ?Rgb = null,
- palette: ?[16]Rgb,
+ line_number: Rgb,
+ rail: Rgb,
+ rail_thumb: Rgb,
+ /// A message's error ink (colors.Chrome's severities): diagnostic.error's,
+ /// else error's, else the theme's red (UX E3: neonotte's diagnostic.error
+ /// is an underline only).
+ @"error": ?Rgb = null,
+ ansi: ?[16]Rgb,
};
pub fn main(init: std.process.Init) !void {
@@ -142,22 +141,22 @@ fn emit(w: *std.Io.Writer, t: Theme) !void {
const info = @typeInfo(Theme).@"struct";
inline for (info.field_names, info.field_types) |name, T| {
if (comptime std.mem.eql(u8, name, "name")) continue;
- if (comptime std.mem.eql(u8, name, "palette")) continue;
- try w.print(" .{s} = ", .{name});
+ if (comptime std.mem.eql(u8, name, "ansi")) continue;
+ try w.print(" .{f} = ", .{std.zig.fmtId(name)});
if (comptime @typeInfo(T) == .optional) {
if (@field(t, name)) |c| try rgb(w, c) else try w.writeAll("null");
} else try rgb(w, @field(t, name));
try w.writeAll(",\n");
}
- if (t.palette) |p| {
- try w.writeAll(" .palette = .{\n");
+ if (t.ansi) |p| {
+ try w.writeAll(" .ansi = .{\n");
for (p) |c| {
try w.writeAll(" ");
try rgb(w, c);
try w.writeAll(",\n");
}
try w.writeAll(" },\n");
- } else try w.writeAll(" .palette = null,\n");
+ } else try w.writeAll(" .ansi = null,\n");
try w.writeAll("};\n");
}
@@ -270,37 +269,36 @@ fn resolve(arena: std.mem.Allocator, tomls: *const std.StringHashMapUnmanaged(To
return .{ .path = t.path, .keys = keys, .palette = palette };
}
-/// A resolved helix theme mapped onto pardes's fourteen fields.
+/// A resolved helix theme mapped onto pardes's fields (core/theme_schema.zig).
///
/// EVERY FALLBACK HERE IS HELIX'S OWN RULE, which is why none of them is fatal:
/// an unstyled scope wears `ui.text`, an unpainted cell wears `ui.background`,
/// and a theme that styles neither is saying "wear whatever the terminal is
/// already wearing" (the base16/term16/transparent themes exist precisely to do
-/// that). pardes spells that last step as a null bg/fg, so those two pass
-/// straight through — but the other twelve fields are RGB and cannot be null, so
+/// that). pardes spells that last step as a null page/text, so those two pass
+/// straight through — but the other fields are RGB and cannot be null, so
/// they need a concrete stand-in for "the terminal's", and that is the default
/// palette's ink and page below. Field by field:
///
-/// bg ui.background.bg, else null = the host terminal's own cell
-/// fg ui.text.fg, else null = ditto
-/// box ui.cursor.primary.bg, else ui.cursor.bg, else keyword.fg,
+/// page ui.background.bg, else null = the host terminal's own cell
+/// text ui.text.fg, else null = ditto
+/// accent ui.cursor.primary.bg, else ui.cursor.bg, else keyword.fg,
/// else ink — skipping any of them that IS the page (see
/// firstNotPage)
-/// box_dim,
-/// scroll_thumb,
-/// sel_bg ui.selection.bg, else ui.selection.primary.bg, else
+/// rail_thumb,
+/// selection ui.selection.bg, else ui.selection.primary.bg, else
/// ui.selection.fg, same page-skipping, else page. No selection
/// colour anywhere means the author drew no selection either,
-/// and a dim box the colour of the page is the honest rendering
-/// of that — no theme in the vendored set actually gets there
-/// sel_fg ui.selection.fg, unless that IS sel_bg, else whichever of
-/// ink and page the highlight is farther from
-/// tag_bg,
-/// scroll_track ui.statusline.bg, else page
-/// tag_fg ui.statusline.fg, else ink
-/// kw/str/comment their scope's fg, else ink (helix: unstyled = ui.text)
-/// num constant.numeric.fg, else constant.fg, else ink
-/// lineno ui.linenr.fg, else ink
+/// and a selection the colour of the page is the honest
+/// rendering of that — no theme in the vendored set gets there
+/// selection_text ui.selection.fg, unless that IS the selection, else
+/// whichever of ink and page the highlight is farther from
+/// tag,
+/// rail ui.statusline.bg, else page
+/// tag_text ui.statusline.fg, else ink
+/// keyword/string/comment their scope's fg, else ink (helix: unstyled = ui.text)
+/// number constant.numeric.fg, else constant.fg, else ink
+/// line_number ui.linenr.fg, else ink
fn helixTheme(arena: std.mem.Allocator, stem: []const u8, h: Helix) !Theme {
const fg = h.get("ui.text", .fg);
const bg = h.get("ui.background", .bg);
@@ -345,28 +343,27 @@ fn helixTheme(arena: std.mem.Allocator, stem: []const u8, h: Helix) !Theme {
.name = try slug(arena, stem),
// `palette` stays null: helix leaves the colors a PROGRAM emits alone,
// and so do we.
- .bg = bg,
- .fg = fg,
- .sel_bg = sel,
- .sel_fg = if (named_ink) |c| (if (std.mem.eql(u8, &c, &sel)) sel_far else c) else sel_far,
- .tag_bg = h.get("ui.statusline", .bg) orelse page,
- .tag_fg = h.get("ui.statusline", .fg) orelse ink,
- .box = box,
- .box_dim = sel,
- .kw = h.get("keyword", .fg) orelse ink,
- .str = h.get("string", .fg) orelse ink,
+ .page = bg,
+ .text = fg,
+ .selection = sel,
+ .selection_text = if (named_ink) |c| (if (std.mem.eql(u8, &c, &sel)) sel_far else c) else sel_far,
+ .tag = h.get("ui.statusline", .bg) orelse page,
+ .tag_text = h.get("ui.statusline", .fg) orelse ink,
+ .accent = box,
+ .keyword = h.get("keyword", .fg) orelse ink,
+ .string = h.get("string", .fg) orelse ink,
// most themes only colour `constant`; the ones that split out numbers
// are being more specific, so they win
- .num = h.first(&.{ .{ "constant.numeric", .fg }, .{ "constant", .fg } }) orelse ink,
+ .number = h.first(&.{ .{ "constant.numeric", .fg }, .{ "constant", .fg } }) orelse ink,
.comment = h.get("comment", .fg) orelse ink,
- .lineno = h.get("ui.linenr", .fg) orelse ink,
+ .line_number = h.get("ui.linenr", .fg) orelse ink,
// the scrollbar is chrome, so it takes the chrome colors: the tag bar's
// own background for the track, the selection (one step brighter than
// anything else in the theme's greys) for the thumb riding it
- .scroll_track = h.get("ui.statusline", .bg) orelse page,
- .scroll_thumb = sel,
- .diagnostic_error = h.first(&.{ .{ "diagnostic.error", .fg }, .{ "error", .fg } }) orelse h.color("red"),
- .palette = null,
+ .rail = h.get("ui.statusline", .bg) orelse page,
+ .rail_thumb = sel,
+ .@"error" = h.first(&.{ .{ "diagnostic.error", .fg }, .{ "error", .fg } }) orelse h.color("red"),
+ .ansi = null,
};
}
@@ -555,8 +552,8 @@ fn readZed(arena: std.mem.Allocator, gpa: std.mem.Allocator, path: []const u8, t
// name rather than a suffix that appears only on the eight that
// happen to clash today
.name = try std.fmt.allocPrint(arena, "{s}_zed", .{try slug(arena, (v.get("name") orelse std.process.fatal("{s}: a variant has no `name`", .{path})).string)}),
- .bg = z.need("editor.background"),
- .fg = z.need("editor.foreground"),
+ .page = z.need("editor.background"),
+ .text = z.need("editor.foreground"),
// zed's TEXT selection is `players[0].selection`, and it is a 24%
// alpha over the page — the colour on screen is the composite, not
// the value. pardes paints opaque cells and `hex` drops alpha, so
@@ -565,24 +562,23 @@ fn readZed(arena: std.mem.Allocator, gpa: std.mem.Allocator, path: []const u8, t
// selected" fill, which is the question actually being asked. The
// ink then stays the editor's own text colour, because that fill is
// always a step off the background and never off the text.
- .sel_bg = z.need("element.selected"),
- .sel_fg = z.need("editor.foreground"),
- .tag_bg = z.need("status_bar.background"),
- .tag_fg = z.need("text.muted"),
+ .selection = z.need("element.selected"),
+ .selection_text = z.need("editor.foreground"),
+ .tag = z.need("status_bar.background"),
+ .tag_text = z.need("text.muted"),
// zed names its accent, so the move box does not have to be guessed
// out of the cursor the way it is for a helix theme
- .box = z.need("text.accent"),
- .box_dim = z.need("border"),
- .kw = z.syn(syntax, "keyword"),
- .str = z.syn(syntax, "string"),
- .num = z.syn(syntax, "number"),
+ .accent = z.need("text.accent"),
+ .keyword = z.syn(syntax, "keyword"),
+ .string = z.syn(syntax, "string"),
+ .number = z.syn(syntax, "number"),
.comment = z.syn(syntax, "comment"),
- .lineno = z.need("editor.line_number"),
- .scroll_track = z.need("scrollbar.thumb.border"),
- .scroll_thumb = z.need("scrollbar.thumb.background"),
+ .line_number = z.need("editor.line_number"),
+ .rail = z.need("scrollbar.thumb.border"),
+ .rail_thumb = z.need("scrollbar.thumb.background"),
// its status colour, else the palette's red (colors.zig)
- .diagnostic_error = if (z.style.get("error") != null) z.need("error") else null,
- .palette = pal,
+ .@"error" = if (z.style.get("error") != null) z.need("error") else null,
+ .ansi = pal,
});
}
}