diff options
Diffstat (limited to 'src/config.zig')
| -rw-r--r-- | src/config.zig | 111 |
1 files changed, 52 insertions, 59 deletions
diff --git a/src/config.zig b/src/config.zig index 4f2802cc..9d5f392d 100644 --- a/src/config.zig +++ b/src/config.zig @@ -1119,16 +1119,35 @@ pub const Runtime = struct { action: Action, /// What it does, one sentence: /commands lists it after the word. doc: []const u8, - availability: ?Capability = null, pub fn enabled(setting: Setting, capabilities: Capabilities) bool { - const capability = setting.availability orelse return true; + const capability = availability(setting.action) orelse return true; return switch (capability) { inline else => |field| @field(capabilities, @tagName(field)), }; } }; + /// What a setting needs of the shell, by what it does. A toggle is plain + /// state any shell can hold, except one for what only some shells draw: + /// that one exists where they do. + pub fn availability(action: Action) ?Capability { + return switch (action) { + .font, .tagline_size => .font_picker, + .window_opacity => .window_opacity, + .window_blur => .window_blur, + .transition => .panel_transitions, + .scene, .shader, .shader_animation => .scene_shaders, + .lift, .grip_width => .lift, + .toggle => |field| switch (field) { + .ligatures => .ligatures, + .cursor_blink, .selection_glow, .hover_glow, .occlusion, .parallax => .lift, + else => null, + }, + else => null, + }; + } + // The builtin registry and DumpConfig report share this command table. pub const settings = [_]Setting{ .{ .word = "Colors", .action = .{ .toggle = .colors }, .doc = "Syntax colours in text panes, on or off." }, @@ -1140,47 +1159,47 @@ pub const Runtime = struct { .{ .word = "SyntaxBold", .action = .{ .toggle = .syntax_bold }, .doc = "Keywords and the like are drawn bold, on or off." }, .{ .word = "Verbose", .action = .{ .toggle = .verbose }, .doc = "A builtin says its own name on the message row as it runs, on or off." }, .{ .word = "MessageAnimation", .action = .{ .toggle = .message_animation }, .doc = "A message falls into its row and dissolves out of it, on or off." }, - .{ .word = "Ligatures", .action = .{ .toggle = .ligatures }, .availability = .ligatures, .doc = "A font's programming ligatures draw across their cells, on or off." }, - .{ .word = "CursorBlink", .action = .{ .toggle = .cursor_blink }, .availability = .lift, .doc = "The cursor blinks, solid while typing, on or off." }, - .{ .word = "SelectionGlow", .action = .{ .toggle = .selection_glow }, .availability = .lift, .doc = "A soft halo of the selection's colour round it in the body, on or off." }, - .{ .word = "HoverGlow", .action = .{ .toggle = .hover_glow }, .availability = .lift, .doc = "A soft underline of light under the word a look-hover would open, on or off." }, - .{ .word = "Occlusion", .action = .{ .toggle = .occlusion }, .availability = .lift, .doc = "Pane bodies darken faintly toward their edges, on or off." }, - .{ .word = "Parallax", .action = .{ .toggle = .parallax }, .availability = .lift, .doc = "A theme's page pattern moves with the text at a quarter of its speed, on or off." }, + .{ .word = "Ligatures", .action = .{ .toggle = .ligatures }, .doc = "A font's programming ligatures draw across their cells, on or off." }, + .{ .word = "CursorBlink", .action = .{ .toggle = .cursor_blink }, .doc = "The cursor blinks, solid while typing, on or off." }, + .{ .word = "SelectionGlow", .action = .{ .toggle = .selection_glow }, .doc = "A soft halo of the selection's colour round it in the body, on or off." }, + .{ .word = "HoverGlow", .action = .{ .toggle = .hover_glow }, .doc = "A soft underline of light under the word a look-hover would open, on or off." }, + .{ .word = "Occlusion", .action = .{ .toggle = .occlusion }, .doc = "Pane bodies darken faintly toward their edges, on or off." }, + .{ .word = "Parallax", .action = .{ .toggle = .parallax }, .doc = "A theme's page pattern moves with the text at a quarter of its speed, on or off." }, .{ .word = "JumpTrail", .action = .{ .toggle = .jump_trail }, .doc = "In a terminal, a jump of the cursor leaves a short trail that fades, on or off." }, .{ .word = "ChipShadow", .action = .{ .toggle = .chip_shadow }, .doc = "In a terminal, a notice chip casts a cell's shadow right and down, on or off." }, .{ .word = "ThumbFlash", .action = .{ .toggle = .thumb_flash }, .doc = "In a terminal, a pane's scroll thumb brightens as it scrolls and fades back, on or off." }, .{ .word = "ProgramEsc", .action = .{ .toggle = .program_esc }, .doc = "In a raw terminal, Esc goes to the program and Shift-Esc backs out, on; off (the default) swaps them." }, - .{ .word = "Lift", .action = .lift, .availability = .lift, .doc = "How the focused pane stands off the page: off, shadow, rim or auto." }, + .{ .word = "Lift", .action = .lift, .doc = "How the focused pane stands off the page: off, shadow, rim or auto." }, .{ .word = "Motion", .action = .motion, .doc = "How animations move: off, crisp, smooth, bouncy or playful." }, .{ .word = "InactiveDim", .action = .inactive_dim, .doc = "Fade the unfocused panes' text by a percentage, 0 through 100, 0 off." }, - .{ .word = "GripWidth", .action = .grip_width, .availability = .lift, .doc = "The grip and scrollbar width, as a percent of the theme's rail." }, + .{ .word = "GripWidth", .action = .grip_width, .doc = "The grip and scrollbar width, as a percent of the theme's rail." }, .{ .word = "MessageLinger", .action = .{ .message_ms = .linger }, .doc = "How long, in milliseconds, a message stays after what dismisses it." }, .{ .word = "MessageFall", .action = .{ .message_ms = .fall }, .doc = "How long, in milliseconds, a message takes to fall into its row." }, .{ .word = "MessageDissolve", .action = .{ .message_ms = .dissolve }, .doc = "How long, in milliseconds, a message takes to dissolve." }, .{ .word = "DumpDir", .action = .dump_dir, .doc = "The directory Dump writes to and a relative Restore reads from; bare, the default." }, .{ .word = "Theme", .action = .theme, .doc = "Switch to the named theme." }, .{ .word = "Shell", .action = .shell, .doc = "The shell new terminals run; bare, $SHELL if it is executable, else /bin/sh." }, - .{ .word = "Font", .action = .font, .availability = .font_picker, .doc = "The body font, by name or path, and its size." }, - .{ .word = "TaglineSize", .action = .tagline_size, .availability = .font_picker, .doc = "Scale the tag font, a percentage." }, - .{ .word = "WindowOpacity", .action = .window_opacity, .availability = .window_opacity, .doc = "The window's opacity, a percentage." }, - .{ .word = "WindowBlur", .action = .window_blur, .availability = .window_blur, .doc = "The blur behind a translucent window, a radius." }, - .{ .word = "PanelSlide", .action = .{ .transition = .slide }, .availability = .panel_transitions, .doc = "Panes slide in and out as they open and close, on or off." }, - .{ .word = "PanelZoom", .action = .{ .transition = .zoom }, .availability = .panel_transitions, .doc = "Panes zoom in and out as they open and close, on or off." }, - .{ .word = "PanelDissolve", .action = .{ .transition = .dissolve }, .availability = .panel_transitions, .doc = "Panes dissolve in and out as they open and close, on or off." }, - .{ .word = "PanelAscii", .action = .{ .transition = .ascii }, .availability = .panel_transitions, .doc = "Panes open and close through a scatter of ASCII, on or off." }, - .{ .word = "PanelVertical", .action = .{ .transition = .vertical }, .availability = .panel_transitions, .doc = "Panes open and close with a vertical wipe, on or off." }, - .{ .word = "PanelEdges", .action = .{ .transition = .edges }, .availability = .panel_transitions, .doc = "Panes open and close from their edges, on or off." }, - .{ .word = "PanelFall", .action = .{ .transition = .fall }, .availability = .panel_transitions, .doc = "Panes fall into place as they open, on or off." }, - .{ .word = "PanelWave", .action = .{ .transition = .wave }, .availability = .panel_transitions, .doc = "Panes open and close in a wave, on or off." }, - .{ .word = "PanelCurtain", .action = .{ .transition = .curtain }, .availability = .panel_transitions, .doc = "Panes open and close like a curtain, on or off." }, - .{ .word = "PanelScramble", .action = .{ .transition = .scramble }, .availability = .panel_transitions, .doc = "Panes open and close through scrambled text, on or off." }, - .{ .word = "PanelType", .action = .{ .transition = .typewriter }, .availability = .panel_transitions, .doc = "Panes type themselves in as they open, on or off." }, - .{ .word = "Crt", .action = .{ .scene = .crt }, .availability = .scene_shaders, .doc = "The bundled CRT post pass over the window, on or off." }, - .{ .word = "Bloom", .action = .{ .scene = .bloom }, .availability = .scene_shaders, .doc = "The brightest ink glows a little: a level, 0 (off) through 3." }, - .{ .word = "Vignette", .action = .{ .scene = .vignette }, .availability = .scene_shaders, .doc = "The window's corners fall into shade: a level, 0 (off) through 3." }, - .{ .word = "Grain", .action = .{ .scene = .grain }, .availability = .scene_shaders, .doc = "The page takes a fine, still grain, like paper: a level, 0 (off) through 3." }, - .{ .word = "Shader", .action = .shader, .availability = .scene_shaders, .doc = "A Shadertoy file into the post chain, or out of it, compiled again when saved; off empties the chain." }, - .{ .word = "ShaderAnimation", .action = .shader_animation, .availability = .scene_shaders, .doc = "When the post chain animates on its own: off, on (while focused) or always." }, + .{ .word = "Font", .action = .font, .doc = "The body font, by name or path, and its size." }, + .{ .word = "TaglineSize", .action = .tagline_size, .doc = "Scale the tag font, a percentage." }, + .{ .word = "WindowOpacity", .action = .window_opacity, .doc = "The window's opacity, a percentage." }, + .{ .word = "WindowBlur", .action = .window_blur, .doc = "The blur behind a translucent window, a radius." }, + .{ .word = "PanelSlide", .action = .{ .transition = .slide }, .doc = "Panes slide in and out as they open and close, on or off." }, + .{ .word = "PanelZoom", .action = .{ .transition = .zoom }, .doc = "Panes zoom in and out as they open and close, on or off." }, + .{ .word = "PanelDissolve", .action = .{ .transition = .dissolve }, .doc = "Panes dissolve in and out as they open and close, on or off." }, + .{ .word = "PanelAscii", .action = .{ .transition = .ascii }, .doc = "Panes open and close through a scatter of ASCII, on or off." }, + .{ .word = "PanelVertical", .action = .{ .transition = .vertical }, .doc = "Panes open and close with a vertical wipe, on or off." }, + .{ .word = "PanelEdges", .action = .{ .transition = .edges }, .doc = "Panes open and close from their edges, on or off." }, + .{ .word = "PanelFall", .action = .{ .transition = .fall }, .doc = "Panes fall into place as they open, on or off." }, + .{ .word = "PanelWave", .action = .{ .transition = .wave }, .doc = "Panes open and close in a wave, on or off." }, + .{ .word = "PanelCurtain", .action = .{ .transition = .curtain }, .doc = "Panes open and close like a curtain, on or off." }, + .{ .word = "PanelScramble", .action = .{ .transition = .scramble }, .doc = "Panes open and close through scrambled text, on or off." }, + .{ .word = "PanelType", .action = .{ .transition = .typewriter }, .doc = "Panes type themselves in as they open, on or off." }, + .{ .word = "Crt", .action = .{ .scene = .crt }, .doc = "The bundled CRT post pass over the window, on or off." }, + .{ .word = "Bloom", .action = .{ .scene = .bloom }, .doc = "The brightest ink glows a little: a level, 0 (off) through 3." }, + .{ .word = "Vignette", .action = .{ .scene = .vignette }, .doc = "The window's corners fall into shade: a level, 0 (off) through 3." }, + .{ .word = "Grain", .action = .{ .scene = .grain }, .doc = "The page takes a fine, still grain, like paper: a level, 0 (off) through 3." }, + .{ .word = "Shader", .action = .shader, .doc = "A Shadertoy file into the post chain, or out of it, compiled again when saved; off empties the chain." }, + .{ .word = "ShaderAnimation", .action = .shader_animation, .doc = "When the post chain animates on its own: off, on (while focused) or always." }, .{ .word = "Placement", .action = .{ .choice = .placement }, .doc = "Where a new pane goes: acme, as makenewwindow does, or pardes, the older rules." }, .{ .word = "BootShell", .action = .{ .choice = .boot_shell }, .doc = "A document dropped where a lone untouched shell stands: keep the shell, or replace it." }, .{ .word = "LookWord", .action = .{ .choice = .look_word }, .doc = "A plain word looked at: search selects its next place in the pane, list lists every place in a +Search." }, @@ -1221,32 +1240,6 @@ pub const Runtime = struct { if (setting.word.len == 0) @compileError("runtime setting has an empty command word"); for (settings[i + 1 ..]) |later| if (std.mem.eql(u8, setting.word, later.word)) @compileError("duplicate runtime setting command word: " ++ setting.word); - switch (setting.action) { - .font, .tagline_size => if (setting.availability != .font_picker) - @compileError("native font settings must use the font-picker capability"), - .window_opacity => if (setting.availability != .window_opacity) - @compileError("window opacity must use the window-opacity capability"), - .window_blur => if (setting.availability != .window_blur) - @compileError("window blur must use the window-blur capability"), - .transition => if (setting.availability != .panel_transitions) - @compileError("panel effects must use the panel-transition capability"), - .scene, .shader, .shader_animation => if (setting.availability != .scene_shaders) - @compileError("scene effects must use the scene-shader capability"), - // A toggle is plain state any shell can hold, except one for - // what only some shells draw: that one exists where they do. - .lift, .grip_width => if (setting.availability != .lift) - @compileError("Lift and GripWidth must use the lift capability (a pixel shell's)"), - .toggle => |field| if (field == .ligatures) { - if (setting.availability != .ligatures) - @compileError("the ligatures toggle must use the ligatures capability"); - } else if (field == .cursor_blink or field == .selection_glow or field == .hover_glow or field == .occlusion or field == .parallax) { - if (setting.availability != .lift) - @compileError("CursorBlink, SelectionGlow, HoverGlow, Occlusion and Parallax must use the lift capability (a pixel shell's)"); - } else if (setting.availability != null) - @compileError("unconditional toggles cannot carry a backend capability"), - else => if (setting.availability != null) - @compileError("unconditional settings cannot carry a backend capability"), - } } for (std.enums.values(Toggle)) |field| if (actionCount(.{ .toggle = field }) != 1) @compileError("runtime toggle must occur exactly once: " ++ @tagName(field)); @@ -1726,7 +1719,7 @@ pub const Runtime = struct { var state: Runtime = .{}; try std.testing.expectEqual(@as(u8, 100), state.window_opacity); try std.testing.expect(state.window_opacity_pending); - try std.testing.expectEqual(Capability.window_opacity, setting.availability.?); + try std.testing.expectEqual(Capability.window_opacity, availability(setting.action).?); for ([_][]const u8{ "0", " 85\n", "100" }, [_]u8{ 0, 85, 100 }) |argument, expected| { state.window_opacity_pending = false; @@ -1751,7 +1744,7 @@ pub const Runtime = struct { const setting = find("WindowBlur").?; var state: Runtime = .{}; try std.testing.expectEqual(@as(u8, 0), state.window_blur); - try std.testing.expectEqual(Capability.window_blur, setting.availability.?); + try std.testing.expectEqual(Capability.window_blur, availability(setting.action).?); for ([_][]const u8{ "0", " 40\n", "100" }, [_]u8{ 0, 40, 100 }) |argument, expected| { try std.testing.expect(apply(&state, setting, argument)); try std.testing.expectEqual(expected, state.window_blur); |
