Merge pull request #1281 from jcollie/sort-list-colors

sort output from +list-colors
This commit is contained in:
Mitchell Hashimoto
2024-01-11 07:57:36 -08:00
committed by GitHub

View File

@ -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;
@ -23,10 +22,24 @@ pub fn run(alloc: std.mem.Allocator) !u8 {
const stdout = std.io.getStdOut().writer();
inline for (x11_color.map.kvs) |kv| {
const name = kv.key;
const rgb = kv.value;
try stdout.print("{s} = #{x:0>2}{x:0>2}{x:0>2}\n", .{ name, rgb.r, rgb.g, rgb.b });
var keys = std.ArrayList([]const u8).init(alloc);
defer keys.deinit();
for (x11_color.map.kvs) |kv| try keys.append(kv.key);
std.mem.sortUnstable([]const u8, keys.items, {}, struct {
fn lessThan(_: void, lhs: []const u8, rhs: []const u8) bool {
return std.ascii.orderIgnoreCase(lhs, rhs) == .lt;
}
}.lessThan);
for (keys.items) |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,
});
}
return 0;