mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
cli/list-colors: use unstable sort, sort in-place on arraylist
This commit is contained in:
@ -8,10 +8,6 @@ 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
|
/// The "list-colors" command is used to list all the named RGB colors in
|
||||||
/// Ghostty.
|
/// Ghostty.
|
||||||
pub fn run(alloc: std.mem.Allocator) !u8 {
|
pub fn run(alloc: std.mem.Allocator) !u8 {
|
||||||
@ -27,17 +23,23 @@ pub fn run(alloc: std.mem.Allocator) !u8 {
|
|||||||
const stdout = std.io.getStdOut().writer();
|
const stdout = std.io.getStdOut().writer();
|
||||||
|
|
||||||
var keys = std.ArrayList([]const u8).init(alloc);
|
var keys = std.ArrayList([]const u8).init(alloc);
|
||||||
|
defer keys.deinit();
|
||||||
|
for (x11_color.map.kvs) |kv| try keys.append(kv.key);
|
||||||
|
|
||||||
inline for (x11_color.map.kvs) |kv| {
|
std.mem.sortUnstable([]const u8, keys.items, {}, struct {
|
||||||
try keys.append(kv.key);
|
fn lessThan(_: void, lhs: []const u8, rhs: []const u8) bool {
|
||||||
}
|
return std.ascii.orderIgnoreCase(lhs, rhs) == .lt;
|
||||||
|
}
|
||||||
|
}.lessThan);
|
||||||
|
|
||||||
const sorted = try keys.toOwnedSlice();
|
for (keys.items) |name| {
|
||||||
std.sort.insertion([]const u8, sorted, {}, cmp);
|
|
||||||
|
|
||||||
for (sorted) |name| {
|
|
||||||
const rgb = x11_color.map.get(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 });
|
try stdout.print("{s} = #{x:0>2}{x:0>2}{x:0>2}\n", .{
|
||||||
|
name,
|
||||||
|
rgb.r,
|
||||||
|
rgb.g,
|
||||||
|
rgb.b,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user