mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-08 10:56:34 +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
@@ -5,6 +5,7 @@ const list_fonts = @import("list_fonts.zig");
|
||||
const version = @import("version.zig");
|
||||
const list_keybinds = @import("list_keybinds.zig");
|
||||
const list_themes = @import("list_themes.zig");
|
||||
const list_colors = @import("list_colors.zig");
|
||||
|
||||
/// Special commands that can be invoked via CLI flags. These are all
|
||||
/// invoked by using `+<action>` as a CLI flag. The only exception is
|
||||
@@ -22,6 +23,9 @@ pub const Action = enum {
|
||||
/// List available themes
|
||||
@"list-themes",
|
||||
|
||||
/// List named RGB colors
|
||||
@"list-colors",
|
||||
|
||||
pub const Error = error{
|
||||
/// Multiple actions were detected. You can specify at most one
|
||||
/// action on the CLI otherwise the behavior desired is ambiguous.
|
||||
@@ -62,6 +66,7 @@ pub const Action = enum {
|
||||
.@"list-fonts" => try list_fonts.run(alloc),
|
||||
.@"list-keybinds" => try list_keybinds.run(alloc),
|
||||
.@"list-themes" => try list_themes.run(alloc),
|
||||
.@"list-colors" => try list_colors.run(alloc),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
32
src/cli/list_colors.zig
Normal file
32
src/cli/list_colors.zig
Normal file
@@ -0,0 +1,32 @@
|
||||
const std = @import("std");
|
||||
const inputpkg = @import("../input.zig");
|
||||
const args = @import("args.zig");
|
||||
const RGBName = @import("rgb_names").RGBName;
|
||||
|
||||
pub const Options = struct {
|
||||
pub fn deinit(self: Options) void {
|
||||
_ = self;
|
||||
}
|
||||
};
|
||||
|
||||
/// The "list-colors" command is used to list all the named RGB colors in
|
||||
/// Ghostty.
|
||||
pub fn run(alloc: std.mem.Allocator) !u8 {
|
||||
var opts: Options = .{};
|
||||
defer opts.deinit();
|
||||
|
||||
{
|
||||
var iter = try std.process.argsWithAllocator(alloc);
|
||||
defer iter.deinit();
|
||||
try args.parse(Options, alloc, &opts, &iter);
|
||||
}
|
||||
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
|
||||
inline for (std.meta.fields(RGBName)) |f| {
|
||||
const rgb = @field(RGBName, f.name).toRGB();
|
||||
try stdout.print("{s} = #{x:0>2}{x:0>2}{x:0>2}\n", .{ f.name, rgb.r, rgb.g, rgb.b });
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user