summaryrefslogtreecommitdiff
path: root/src/config.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.zig')
-rw-r--r--src/config.zig63
1 files changed, 48 insertions, 15 deletions
diff --git a/src/config.zig b/src/config.zig
index 24c48770..fb38e4dd 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -119,6 +119,7 @@ pub const leader_path = paths: {
if (builtins.capabilities.window_opacity) table.set(.WindowOpacity, null);
if (builtins.capabilities.window_blur) table.set(.WindowBlur, null);
if (builtins.capabilities.ligatures) table.set(.Ligatures, null);
+ if (builtins.capabilities.lift) table.set(.CursorBlink, null);
if (builtins.capabilities.lift) table.set(.Lift, null);
table.set(.Motion, null);
table.set(.InactiveDim, null);
@@ -647,6 +648,10 @@ pub const Runtime = struct {
verbose: bool = true,
/// A message falls into its row and dissolves out of it.
message_animation: bool = true,
+ /// The cursor blinks, a pixel shell's (docs/render-pipeline.md ยง5.4):
+ /// solid while typing and for half a second after, eased at each edge,
+ /// solid again after ten idle seconds.
+ cursor_blink: bool = true,
/// How long a message stays after the key or click that dismisses it.
message_linger_ms: u16 = 800,
/// How long its ease-in fall into the row takes.
@@ -863,7 +868,7 @@ pub const Runtime = struct {
/// The message timings a setting word sets, each in milliseconds.
pub const MessageTime = enum { linger, fall, dissolve };
- pub const Toggle = enum { colors, wrap, tree_context_tag_style, tag_bottom, debug, focus_tint, syntax_bold, verbose, message_animation, ligatures };
+ pub const Toggle = enum { colors, wrap, tree_context_tag_style, tag_bottom, debug, focus_tint, syntax_bold, verbose, message_animation, ligatures, cursor_blink };
/// The bundled post pass, a Shadertoy file in shaders/post/.
pub const Scene = enum { crt };
@@ -918,6 +923,7 @@ pub const Runtime = struct {
.{ .word = "Verbose", .action = .{ .toggle = .verbose } },
.{ .word = "MessageAnimation", .action = .{ .toggle = .message_animation } },
.{ .word = "Ligatures", .action = .{ .toggle = .ligatures }, .availability = .ligatures },
+ .{ .word = "CursorBlink", .action = .{ .toggle = .cursor_blink }, .availability = .lift },
.{ .word = "Lift", .action = .lift, .availability = .lift },
.{ .word = "Motion", .action = .motion },
.{ .word = "InactiveDim", .action = .inactive_dim },
@@ -990,6 +996,9 @@ pub const Runtime = struct {
.toggle => |field| if (field == .ligatures) {
if (setting.availability != .ligatures)
@compileError("the ligatures toggle must use the ligatures capability");
+ } else if (field == .cursor_blink) {
+ if (setting.availability != .lift)
+ @compileError("CursorBlink 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)
@@ -1104,20 +1113,12 @@ pub const Runtime = struct {
}
return state.post.set(null, path, null);
},
- .shader_animation => {
- const text = std.mem.trim(u8, argument orelse return false, " \t\r\n");
- state.shader_animation = std.meta.stringToEnum(ShaderAnimation, text) orelse return false;
- },
+ .shader_animation => state.shader_animation = stepped(ShaderAnimation, state.shader_animation, argument) orelse return false,
// Bare, it steps to the next word, as a tag word should.
.choice => |which| switch (which) {
inline else => |field| {
const now = &@field(state, @tagName(field));
- const T = @TypeOf(now.*);
- const text = std.mem.trim(u8, argument orelse "", " \t\r\n");
- now.* = if (text.len == 0)
- @enumFromInt((@as(usize, @intFromEnum(now.*)) + 1) % std.enums.values(T).len)
- else
- std.meta.stringToEnum(T, text) orelse return false;
+ now.* = stepped(@TypeOf(now.*), now.*, argument) orelse return false;
},
},
.lift => {
@@ -1129,10 +1130,7 @@ pub const Runtime = struct {
else
std.meta.stringToEnum(LiftStyle, text) orelse return false;
},
- .motion => {
- const text = std.mem.trim(u8, argument orelse return false, " \t\r\n");
- state.motion = std.meta.stringToEnum(animation.Motion.Flavour, text) orelse return false;
- },
+ .motion => state.motion = stepped(animation.Motion.Flavour, state.motion, argument) orelse return false,
.inactive_dim => {
const text = std.mem.trim(u8, argument orelse return false, " \t\r\n%");
const percent = std.fmt.parseInt(u8, text, 10) catch return false;
@@ -1150,6 +1148,40 @@ pub const Runtime = struct {
return true;
}
+ /// The values a setting that chooses among words takes, for a refusal to
+ /// name; null for one that takes a number, a path or a name. Bare, each
+ /// of these flips (a two-valued one) or steps to its next value.
+ pub fn choices(action: Action) ?[]const u8 {
+ const words = struct {
+ fn of(comptime T: type) []const u8 {
+ comptime var out: []const u8 = "";
+ inline for (std.meta.fieldNames(T), 0..) |name, i| out = out ++ (if (i > 0) ", " else "") ++ name;
+ return out;
+ }
+ };
+ return switch (action) {
+ .toggle, .transition => "on, off",
+ .choice => |which| switch (which) {
+ inline else => |field| comptime words.of(@FieldType(Runtime, @tagName(field))),
+ },
+ .lift => "on, " ++ comptime words.of(LiftStyle),
+ .motion => comptime words.of(animation.Motion.Flavour),
+ .scene => std.fmt.comptimePrint("on, off, 0-{d}", .{Post.max_level}),
+ .shader_animation => comptime words.of(ShaderAnimation),
+ else => null,
+ };
+ }
+
+ /// The value a choice word names, or bare, the one after `now`; null for
+ /// a word it does not take.
+ fn stepped(comptime T: type, now: T, argument: ?[]const u8) ?T {
+ const text = std.mem.trim(u8, argument orelse "", " \t\r\n");
+ if (text.len > 0) return std.meta.stringToEnum(T, text);
+ const all = std.enums.values(T);
+ const at = std.mem.indexOfScalar(T, all, now) orelse 0;
+ return all[(at + 1) % all.len];
+ }
+
/// What `on`, `off` or nothing after a switch word asks for: null flips
/// it, as a bare tagline word does.
fn switchedTo(argument: ?[]const u8) error{NotOnOrOff}!?bool {
@@ -1618,6 +1650,7 @@ pub const Runtime = struct {
.verbose => "Verbose off\n",
.message_animation => "MessageAnimation off\n",
.ligatures => "Ligatures off\n",
+ .cursor_blink => "CursorBlink off\n",
},
.shell => "Shell requested (new panes) fish\n",
.tagline_size => "TaglineSize 73\n",