From 5258554135e94245244a800011b9eebea9616d3d Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Thu, 11 Jan 2024 00:30:48 -0600 Subject: [PATCH] sort output from +list-colors --- src/cli/list_colors.zig | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cli/list_colors.zig b/src/cli/list_colors.zig index 42c8396d3..fb9631133 100644 --- a/src/cli/list_colors.zig +++ b/src/cli/list_colors.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const inputpkg = @import("../input.zig"); const args = @import("args.zig"); const x11_color = @import("../terminal/main.zig").x11_color; @@ -9,6 +8,10 @@ pub const Options = struct { } }; +fn cmp(_: void, lhs: []const u8, rhs: []const u8) bool { + return std.ascii.lessThanIgnoreCase(lhs, rhs); +} + /// The "list-colors" command is used to list all the named RGB colors in /// Ghostty. pub fn run(alloc: std.mem.Allocator) !u8 { @@ -23,9 +26,17 @@ pub fn run(alloc: std.mem.Allocator) !u8 { const stdout = std.io.getStdOut().writer(); + var keys = std.ArrayList([]const u8).init(alloc); + inline for (x11_color.map.kvs) |kv| { - const name = kv.key; - const rgb = kv.value; + try keys.append(kv.key); + } + + const sorted = try keys.toOwnedSlice(); + std.sort.insertion([]const u8, sorted, {}, cmp); + + for (sorted) |name| { + const rgb = x11_color.map.get(name).?; try stdout.print("{s} = #{x:0>2}{x:0>2}{x:0>2}\n", .{ name, rgb.r, rgb.g, rgb.b }); }