From fbabc963c669d7d403038fdaae9cb4a5415723fb Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Thu, 30 May 2024 10:27:55 -0400 Subject: [PATCH] config: use the standard 'packed struct' behavior --- src/build/fish_completions.zig | 2 +- src/config/Config.zig | 68 ++++------------------------------ 2 files changed, 8 insertions(+), 62 deletions(-) diff --git a/src/build/fish_completions.zig b/src/build/fish_completions.zig index b72360e7dd..c0d2e602db 100644 --- a/src/build/fish_completions.zig +++ b/src/build/fish_completions.zig @@ -12,7 +12,7 @@ pub const fish_completions = comptimeGenerateFishCompletions(); fn comptimeGenerateFishCompletions() []const u8 { comptime { - @setEvalBranchQuota(13000); + @setEvalBranchQuota(14000); var counter = std.io.countingWriter(std.io.null_writer); try writeFishCompletions(&counter.writer()); diff --git a/src/config/Config.zig b/src/config/Config.zig index 981697fcab..0fc6461772 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -642,9 +642,12 @@ keybind: Keybinds = .{}, /// focused, the default working directory will be used (the `working-directory` /// option). /// -/// Valid values are `split`, `tab`, and `window`. You can specify multiple -/// values using a comma-delimited string (`tab` or `split,window`). You -/// can also set this to `true` (always inherit) or `false` (never inherit). +/// The format of this is a list of values to enable separated by commas. If +/// you prefix a value with `no-` then it is disabled. If you omit a feature, +/// its default value is used, so you must explicitly disable features you don't +/// want. +/// +/// Valid values are `split`, `tab`, and `window`. /// /// `split`, `tab`, and `window` are currently only supported on macOS. @"window-inherit-working-directory": WindowInheritWorkingDirectory = .{}, @@ -3496,68 +3499,11 @@ pub const WindowNewTabPosition = enum { end, }; -/// Options for inheriting the working directory of the previous window. +/// See window-inherit-working-directory pub const WindowInheritWorkingDirectory = packed struct { - const Self = @This(); - split: bool = true, tab: bool = true, window: bool = true, - - pub fn parseCLI(self: *Self, _: Allocator, input: ?[]const u8) !void { - const value = input orelse return error.ValueRequired; - const fields = @typeInfo(Self).Struct.fields; - - if (std.mem.eql(u8, value, "true")) { - self.* = .{ .split = true, .tab = true, .window = true }; - return; - } - - if (std.mem.eql(u8, value, "false")) { - self.* = .{ .split = false, .tab = false, .window = false }; - return; - } - - // Enable all of the fields named in the comma-separated value. - self.* = .{ .split = false, .tab = false, .window = false }; - var iter = std.mem.splitSequence(u8, value, ","); - loop: while (iter.next()) |part_raw| { - const part = std.mem.trim(u8, part_raw, whitespace); - - inline for (fields) |field| { - assert(field.type == bool); - if (std.mem.eql(u8, field.name, part)) { - @field(self, field.name) = true; - continue :loop; - } - } - - // No field matched - return error.InvalidValue; - } - } - - test "parseCLI" { - const testing = std.testing; - var arena = ArenaAllocator.init(testing.allocator); - defer arena.deinit(); - const alloc = arena.allocator(); - - var p: Self = .{}; - try p.parseCLI(alloc, "true"); - try testing.expectEqual(Self{ .split = true, .tab = true, .window = true }, p); - - try p.parseCLI(alloc, "false"); - try testing.expectEqual(Self{ .split = false, .tab = false, .window = false }, p); - - try p.parseCLI(alloc, "tab"); - try testing.expectEqual(Self{ .split = false, .tab = true, .window = false }, p); - - try p.parseCLI(alloc, "split,window"); - try testing.expectEqual(Self{ .split = true, .tab = false, .window = true }, p); - - try testing.expectError(error.InvalidValue, p.parseCLI(alloc, "unknown")); - } }; /// See grapheme-width-method