feat: add some home screen customization

This commit is contained in:
CJ van den Berg 2025-03-08 00:59:23 +01:00
parent fab0ff00da
commit 3da2f8d484
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 220 additions and 108 deletions

View file

@ -230,6 +230,26 @@ fn check_all_not_dirty(self: *const Self) command.Result {
return tp.exit("unsaved changes");
}
fn open_style_config(self: *Self, Style: type) command.Result {
const file_name = try root.get_config_file_name(Style);
const style, const style_bufs: [][]const u8 = if (root.exists_config(Style)) blk: {
const style, const style_bufs = root.read_config(Style, self.allocator);
break :blk .{ style, style_bufs };
} else .{ Style{}, &.{} };
defer root.free_config(self.allocator, style_bufs);
var conf = std.ArrayList(u8).init(self.allocator);
defer conf.deinit();
root.write_config_to_writer(Style, style, conf.writer()) catch {};
tui.reset_drag_context();
try self.create_editor();
try command.executeName("open_scratch_buffer", command.fmt(.{
file_name[0 .. file_name.len - ".json".len],
conf.items,
"conf",
}));
if (self.get_active_buffer()) |buffer| buffer.mark_not_ephemeral();
}
const cmds = struct {
pub const Target = Self;
const Ctx = command.Context;
@ -414,27 +434,15 @@ const cmds = struct {
pub const open_gui_config_meta = .{ .description = "Edit gui configuration" };
pub fn open_tabs_style_config(self: *Self, _: Ctx) Result {
const Style = @import("status/tabs.zig").Style;
const file_name = try root.get_config_file_name(Style);
const tab_style, const tab_style_bufs: [][]const u8 = if (root.exists_config(Style)) blk: {
const tab_style, const tab_style_bufs = root.read_config(Style, self.allocator);
break :blk .{ tab_style, tab_style_bufs };
} else .{ Style{}, &.{} };
defer root.free_config(self.allocator, tab_style_bufs);
var conf = std.ArrayList(u8).init(self.allocator);
defer conf.deinit();
root.write_config_to_writer(Style, tab_style, conf.writer()) catch {};
tui.reset_drag_context();
try self.create_editor();
try command.executeName("open_scratch_buffer", command.fmt(.{
file_name[0 .. file_name.len - ".json".len],
conf.items,
"conf",
}));
if (self.get_active_buffer()) |buffer| buffer.mark_not_ephemeral();
try self.open_style_config(@import("status/tabs.zig").Style);
}
pub const open_tabs_style_config_meta: Meta = .{ .description = "Edit tab style" };
pub fn open_home_style_config(self: *Self, _: Ctx) Result {
try self.open_style_config(@import("home.zig").Style);
}
pub const open_home_style_config_meta: Meta = .{ .description = "Edit home screen" };
pub fn create_scratch_buffer(self: *Self, ctx: Ctx) Result {
const args = try ctx.args.clone(self.allocator);
defer self.allocator.free(args.buf);