mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-17 23:31:56 +00:00
add ability to specify RGB colors as names from the X11 rgb name list
This commit is contained in:

committed by
Mitchell Hashimoto

parent
c24d7d6de6
commit
bc1544a3f0
@@ -20,6 +20,7 @@ const Key = @import("key.zig").Key;
|
||||
const KeyValue = @import("key.zig").Value;
|
||||
const ErrorList = @import("ErrorList.zig");
|
||||
const MetricModifier = fontpkg.face.Metrics.Modifier;
|
||||
const RGBName = @import("rgb_names").RGBName;
|
||||
|
||||
const log = std.log.scoped(.config);
|
||||
|
||||
@@ -2139,7 +2140,12 @@ pub const Color = packed struct(u24) {
|
||||
}
|
||||
|
||||
pub fn parseCLI(input: ?[]const u8) !Color {
|
||||
return fromHex(input orelse return error.ValueRequired);
|
||||
if (input == null) return error.ValueRequred;
|
||||
if (RGBName.fromString(input.?)) |name| {
|
||||
const rgb = name.toRGB();
|
||||
return Color{ .r = rgb.r, .g = rgb.g, .b = rgb.b };
|
||||
}
|
||||
return fromHex(input.?);
|
||||
}
|
||||
|
||||
/// Deep copy of the struct. Required by Config.
|
||||
@@ -2188,6 +2194,10 @@ pub const Color = packed struct(u24) {
|
||||
try testing.expectEqual(Color{ .r = 10, .g = 11, .b = 12 }, try Color.fromHex("0A0B0C"));
|
||||
try testing.expectEqual(Color{ .r = 255, .g = 255, .b = 255 }, try Color.fromHex("FFFFFF"));
|
||||
}
|
||||
|
||||
test "fromName" {
|
||||
try std.testing.expectEqual(Color{ .r = 0, .g = 0, .b = 0 }, try Color.parseCLI("black"));
|
||||
}
|
||||
};
|
||||
|
||||
/// Palette is the 256 color palette for 256-color mode. This is still
|
||||
|
Reference in New Issue
Block a user