diff options
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index ed0a07dd..2dac8a59 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -145,6 +145,22 @@ pub const registry = struct { return true; } + /// Whether the word means nothing without its argument (`Mount`, + /// `Msg`, a setting's value), or would ask for it at a prompt (`Find`): + /// a ctl refuses it bare before any line of the write runs. A builtin + /// says `pub const requires_arg = true;` beside `takes_arg`. + pub fn requiresArg(b: Builtin()) bool { + inline for (manualBuiltinList(), 0..) |T, i| + if (@intFromEnum(b) == i) return @hasDecl(T, "requires_arg") and T.requires_arg; + inline for (comptime settingList(), manualBuiltinCount()..) |setting, i| + if (@intFromEnum(b) == i) return switch (setting.action) { + // a switch flips bare, and DumpDir bare is the default + .toggle, .transition, .scene, .dump_dir => false, + .shell, .theme, .font, .tagline_size, .window_opacity, .window_blur, .message_ms => true, + }; + unreachable; + } + pub fn scope(b: Builtin()) Scope { inline for (manualBuiltinList(), 0..) |T, i| if (@intFromEnum(b) == i) return if (@hasDecl(T, "scope")) T.scope else .pane; @@ -237,6 +253,7 @@ comptime { pub const Look = struct { pub const takes_arg = true; + pub const requires_arg = true; // a look's answer is the pane it opens or the place it jumps to; its own // name on the message row would only be noise over that pub const quiet = true; @@ -247,6 +264,7 @@ pub const Look = struct { pub const Exec = struct { pub const takes_arg = true; + pub const requires_arg = true; pub fn run(c: Ctx) void { // the destination pane is Look's business (it focuses what answered); // an execute deliberately leaves you where you were @@ -311,6 +329,7 @@ pub const Detach = struct { pub const Mount = struct { pub const scope: Scope = .session; pub const takes_arg = true; + pub const requires_arg = true; pub const enabled = pardes.hosted; pub fn run(c: Ctx) void { if (comptime !enabled) unreachable; @@ -325,6 +344,7 @@ pub const Mount = struct { pub const Unmount = struct { pub const scope: Scope = .session; pub const takes_arg = true; + pub const requires_arg = true; pub const enabled = pardes.hosted; pub fn run(c: Ctx) void { if (comptime !enabled) unreachable; @@ -339,6 +359,7 @@ pub const Unmount = struct { pub const Msg = struct { pub const takes_arg = true; + pub const requires_arg = true; pub const quiet = true; // it IS the message row pub fn run(c: Ctx) void { if (c.arg) |text| @@ -366,6 +387,7 @@ pub const ThemeSel = struct { pub const ThemeFile = struct { pub const scope: Scope = .session; pub const takes_arg = true; + pub const requires_arg = true; pub const enabled = pardes.hosted; pub fn run(c: Ctx) void { if (comptime enabled) @@ -722,6 +744,7 @@ pub const Changelog = struct { pub const EffectCode = struct { pub const scope: Scope = .session; pub const takes_arg = true; + pub const requires_arg = true; pub const enabled = capabilities.panel_transitions or capabilities.scene_shaders; pub const output: OutputTraits = .{ .name = config.effect_code_buffer }; pub fn run(c: Ctx) void { @@ -737,6 +760,7 @@ pub const EffectCode = struct { pub const Pet = struct { pub const scope: Scope = .session; pub const takes_arg = true; + pub const requires_arg = true; pub const enabled = pardes.platform == .gui; pub fn run(c: Ctx) void { const name = std.mem.trim(u8, c.arg orelse return, " \t\r\n"); @@ -758,6 +782,7 @@ pub const Mini = struct { pub const Find = struct { pub const takes_arg = true; + pub const requires_arg = true; pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true }; pub fn run(c: Ctx) void { const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); @@ -771,6 +796,7 @@ pub const Find = struct { /// matches file CONTENTS under every pane's directory at once. pub const Grep = struct { pub const takes_arg = true; + pub const requires_arg = true; pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); @@ -940,6 +966,7 @@ pub const Subtypes = struct { pub const Rename = struct { pub const takes_arg = true; + pub const requires_arg = true; pub fn run(c: Ctx) void { const a = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); if (a.len > 0) return c.p.lspRequest(c.id, .rename, a); @@ -949,6 +976,7 @@ pub const Rename = struct { pub const WsSymbols = struct { pub const takes_arg = true; + pub const requires_arg = true; pub fn run(c: Ctx) void { const a = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); if (a.len > 0) return c.p.lspRequest(c.id, .workspace_symbols, a); @@ -971,6 +999,7 @@ pub const Lspwhy = struct { pub const Peek = struct { pub const scope: Scope = .session; pub const takes_arg = true; + pub const requires_arg = true; pub const enabled = Board.enabled; pub const output: OutputTraits = .{ .name = config.peek_buffer }; pub fn run(c: Ctx) void { @@ -984,6 +1013,7 @@ pub const Peek = struct { pub const Poke = struct { pub const scope: Scope = .session; pub const takes_arg = true; + pub const requires_arg = true; pub const enabled = Board.enabled; pub fn run(c: Ctx) void { if (comptime enabled) { @@ -996,6 +1026,7 @@ pub const Poke = struct { pub const Hexdump = struct { pub const scope: Scope = .session; pub const takes_arg = true; + pub const requires_arg = true; pub const enabled = Board.enabled; pub const output: OutputTraits = .{ .name = config.hexdump_buffer }; pub fn run(c: Ctx) void { |
