diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/gen_themes.zig | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/tools/gen_themes.zig b/tools/gen_themes.zig index c369b744..62aafcf5 100644 --- a/tools/gen_themes.zig +++ b/tools/gen_themes.zig @@ -124,8 +124,12 @@ pub fn main(init: std.process.Init) !void { t.hit = f.hit; } // sorted, so the ring's tail is the same on every machine whatever order - // the directory happened to be read in - std.mem.sort(Theme, themes.items, {}, byName); + // the directory happened to be read in: a family at a time (a name's + // first word, two themes or more), the lone ones after every family, so + // the picker heads each family once (colors.zig `import_heads`) + var families: std.StringHashMapUnmanaged(u32) = .empty; + for (themes.items) |t| (try families.getOrPutValue(arena, family(t.name), 0)).value_ptr.* += 1; + std.mem.sort(Theme, themes.items, &families, byFamily); var dir = try std.Io.Dir.cwd().openDir(io, args[1], .{}); defer dir.close(io); @@ -150,7 +154,14 @@ fn write(io: std.Io, dir: std.Io.Dir, arena: std.mem.Allocator, stem: []const u8 try file.writeStreamingAll(io, text); } -fn byName(_: void, a: Theme, b: Theme) bool { +fn family(name: []const u8) []const u8 { + return name[0 .. std.mem.indexOfScalar(u8, name, '_') orelse name.len]; +} + +fn byFamily(families: *const std.StringHashMapUnmanaged(u32), a: Theme, b: Theme) bool { + const lone_a = families.get(family(a.name)).? < 2; + const lone_b = families.get(family(b.name)).? < 2; + if (lone_a != lone_b) return lone_b; return std.mem.order(u8, a.name, b.name) == .lt; } |
