refactor: convert whitespace_mode config options to an enum

This commit is contained in:
CJ van den Berg 2025-11-18 12:35:28 +01:00
parent e2009425f5
commit 3dc731d086
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 26 additions and 37 deletions

View file

@ -990,25 +990,20 @@ const cmds = struct {
pub const theme_prev_meta: Meta = .{ .description = "Previous color theme" };
pub fn toggle_whitespace_mode(self: *Self, _: Ctx) Result {
self.config_.whitespace_mode = if (std.mem.eql(u8, self.config_.whitespace_mode, "none"))
"indent"
else if (std.mem.eql(u8, self.config_.whitespace_mode, "indent"))
"leading"
else if (std.mem.eql(u8, self.config_.whitespace_mode, "leading"))
"eol"
else if (std.mem.eql(u8, self.config_.whitespace_mode, "eol"))
"tabs"
else if (std.mem.eql(u8, self.config_.whitespace_mode, "tabs"))
"visible"
else if (std.mem.eql(u8, self.config_.whitespace_mode, "visible"))
"full"
else
"none";
self.config_.whitespace_mode = switch (self.config_.whitespace_mode) {
.none => .indent,
.indent => .leading,
.leading => .eol,
.eol => .tabs,
.tabs => .visible,
.visible => .full,
.full => .none,
};
try save_config();
var buf: [32]u8 = undefined;
const m = try tp.message.fmtbuf(&buf, .{ "whitespace_mode", self.config_.whitespace_mode });
_ = try self.send_widgets(tp.self_pid(), m);
self.logger.print("whitespace rendering {s}", .{self.config_.whitespace_mode});
self.logger.print("whitespace rendering {s}", .{@tagName(self.config_.whitespace_mode)});
}
pub const toggle_whitespace_mode_meta: Meta = .{ .description = "Next whitespace mode" };