Add modal input state and rails

This commit is contained in:
slhx agent
2026-06-21 12:18:13 +02:00
parent 047bae94af
commit 1468675792
4 changed files with 435 additions and 14 deletions
+16 -3
View File
@@ -21,6 +21,8 @@ pub const Action = union(enum) {
quit,
open: []u8,
symbol: symbol_mod.Symbol,
repeat_rail,
restore_last,
not_built: Feature,
pub fn deinit(self: Action, allocator: std.mem.Allocator) void {
@@ -66,7 +68,7 @@ pub const Leader = struct {
if (self.message) |message| return message;
return switch (self.mode) {
.idle => "",
.rail => "leader: s save q quit o open p symbols / search x close",
.rail => "leader: s save q quit o open p symbols r repeat / search x close",
.symbol_rail => symbol_mod.rail_status,
.open_prompt => "open: type path, Enter opens, Esc cancels",
};
@@ -84,6 +86,10 @@ pub const Leader = struct {
return self.open_prompt.items;
}
pub fn isPromptActive(self: *const Leader) bool {
return self.mode == .open_prompt;
}
fn handleIdle(self: *Leader, event: input.Event) Action {
self.message = null;
switch (event) {
@@ -117,6 +123,10 @@ pub const Leader = struct {
self.mode = .symbol_rail;
return .none;
}
if (std.mem.eql(u8, text, "r")) {
self.mode = .idle;
return .repeat_rail;
}
if (std.mem.eql(u8, text, "/")) {
self.mode = .idle;
self.message = "search is not built in this profile yet";
@@ -137,7 +147,10 @@ pub const Leader = struct {
self.message = "leader cancelled";
return .none;
},
.space => return .none,
.space => {
self.mode = .idle;
return .restore_last;
},
else => {
self.mode = .idle;
self.message = "unknown leader key";
@@ -233,7 +246,7 @@ test "regular: space opens a visible leader rail and save dispatches" {
defer leader.deinit();
try expectActionTag(.none, try leader.handleEvent(input.normalize(" ")));
try std.testing.expectEqualStrings("leader: s save q quit o open p symbols / search x close", leader.status());
try std.testing.expectEqualStrings("leader: s save q quit o open p symbols r repeat / search x close", leader.status());
try expectActionTag(.save, try leader.handleEvent(input.normalize("s")));
try std.testing.expect(!leader.isActive());