diff --git a/src/cli/list_themes.zig b/src/cli/list_themes.zig index 6539ad8d7..5de9351b8 100644 --- a/src/cli/list_themes.zig +++ b/src/cli/list_themes.zig @@ -9,6 +9,9 @@ const internal_os = @import("../os/main.zig"); const global_state = &@import("../global.zig").state; pub const Options = struct { + /// If true, show a small preview of the theme. + preview: bool = false, + pub fn deinit(self: Options) void { _ = self; } @@ -23,12 +26,26 @@ pub const Options = struct { /// The `list-themes` command is used to list all the available themes for /// Ghostty. /// -/// Themes require that Ghostty have access to the resources directory. On macOS -/// this is embedded in the app bundle. On Linux, this is usually in `/usr/ -/// share/ghostty`. If you're compiling from source, this is the `zig-out/share/ -/// ghostty` directory. You can also set the `GHOSTTY_RESOURCES_DIR` environment -/// variable to point to the resources directory. Themes live in the `themes` -/// subdirectory of the resources directory. +/// Two different directories will be searched for themes. +/// +/// The first directory is the `themes` subdirectory of your Ghostty +/// configuration directory. This is `$XDG_CONFIG_DIR/ghostty/themes` or +/// `~/.config/ghostty/themes`. +/// +/// The second directory is the `themes` subdirectory of the Ghostty resources +/// directory. Ghostty ships with a multitude of themes that will be installed +/// into this directory. On macOS, this directory is the `Ghostty.app/Contents/ +/// Resources/ghostty/themes`. On Linux, this directory is the `share/ghostty/ +/// themes` (wherever you installed the Ghostty "share" directory). If you're +/// running Ghostty from the source, this is the `zig-out/share/ghostty/themes` +/// directory. +/// +/// You can also set the `GHOSTTY_RESOURCES_DIR` environment variable to point +/// to the resources directory. +/// +/// Flags: +/// +/// * `--preview`: Show a short preview of the theme colors. pub fn run(alloc: Allocator) !u8 { var opts: Options = .{}; defer opts.deinit(); @@ -107,6 +124,40 @@ pub fn run(alloc: Allocator) !u8 { for (themes.items) |theme| { try stdout.print("{s} ({s})\n", .{ theme.theme, @tagName(theme.type) }); + + if (opts.preview) { + var config = try Config.default(alloc); + defer config.deinit(); + if (config.loadFile(config._arena.?.allocator(), theme.path)) |_| { + if (!config._errors.empty()) { + try stderr.print(" Problems were encountered trying to load the theme:\n", .{}); + for (config._errors.list.items) |err| { + try stderr.print(" {s}\n", .{err.message}); + } + } + try stdout.print("\n ", .{}); + for (0..8) |i| { + try stdout.print(" {d:2} \x1b[38;2;{d};{d};{d}m██\x1b[0m", .{ + i, + config.palette.value[i].r, + config.palette.value[i].g, + config.palette.value[i].b, + }); + } + try stdout.print("\n ", .{}); + for (8..16) |i| { + try stdout.print(" {d:2} \x1b[38;2;{d};{d};{d}m██\x1b[0m", .{ + i, + config.palette.value[i].r, + config.palette.value[i].g, + config.palette.value[i].b, + }); + } + try stdout.print("\n\n", .{}); + } else |err| { + try stderr.print("unable to load {s}: {}", .{ theme.path, err }); + } + } } if (count == 0) {