Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add save instruction to +list-themes #4902

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion src/cli/list_themes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const Preview = struct {
normal,
help,
search,
save,
},
color_scheme: vaxis.Color.Scheme,
text_input: vaxis.widgets.TextInput,
Expand Down Expand Up @@ -376,6 +377,8 @@ const Preview = struct {
self.mode = .help;
if (key.matches('/', .{}))
self.mode = .search;
if (key.matchesAny(&.{ vaxis.Key.enter, vaxis.Key.kp_enter }, .{}))
self.mode = .save;
if (key.matchesAny(&.{ 'x', '/' }, .{ .ctrl = true })) {
self.text_input.buf.clearRetainingCapacity();
try self.updateFiltered();
Expand Down Expand Up @@ -430,6 +433,12 @@ const Preview = struct {
try self.text_input.update(.{ .key_press = key });
try self.updateFiltered();
},
.save => {
if (key.matches('q', .{}))
self.should_quit = true;
if (key.matchesAny(&.{ vaxis.Key.escape, vaxis.Key.enter, vaxis.Key.kp_enter }, .{}))
self.mode = .normal;
},
}
},
.color_scheme => |color_scheme| self.color_scheme = color_scheme,
Expand Down Expand Up @@ -673,7 +682,7 @@ const Preview = struct {
.{ .keys = "End", .help = "Go to the end of the list." },
.{ .keys = "/", .help = "Start search." },
.{ .keys = "^X, ^/", .help = "Clear search." },
.{ .keys = "⏎", .help = "Close search window." },
.{ .keys = "⏎", .help = "Save theme or close search window." },
};

for (key_help, 0..) |help, captured_i| {
Expand Down Expand Up @@ -724,6 +733,51 @@ const Preview = struct {
child.fill(.{ .style = self.ui_standard() });
self.text_input.drawWithStyle(child, self.ui_standard());
},
.save => {
const theme = self.themes[self.filtered.items[self.current]];

const width = 90;
const height = 12;
Aaron-212 marked this conversation as resolved.
Show resolved Hide resolved
const child = win.child(
.{
.x_off = win.width / 2 -| width / 2,
.y_off = win.height / 2 -| height / 2,
.width = width,
.height = height,
.border = .{
.where = .all,
.style = self.ui_standard(),
},
},
);

child.fill(.{ .style = self.ui_standard() });

const save_instructions = [_][]const u8{
"To apply this theme, add the following line to your Ghostty configuration:",
"",
try std.fmt.allocPrint(alloc, "theme = {s}", .{theme.theme}),
Aaron-212 marked this conversation as resolved.
Show resolved Hide resolved
"",
"Save the configuration file and then reload it to apply the new theme.",
"For more details on configuration and themes, visit the Ghostty documentation:",
"",
"https://ghostty.org/docs/config/reference",
};

for (save_instructions, 0..) |instruction, captured_i| {
const i: u16 = @intCast(captured_i);
_ = child.printSegment(
.{
.text = instruction,
.style = self.ui_standard(),
},
.{
.row_offset = i + 1,
.col_offset = 2,
},
);
}
},
}
}

Expand Down