diff options
| -rw-r--r-- | core/TagState.zig | 31 | ||||
| -rw-r--r-- | test/behaviour/keys.zig | 7 | ||||
| -rw-r--r-- | test/behaviour/modes.zig | 12 | ||||
| -rw-r--r-- | test/panes.zig | 3 |
4 files changed, 41 insertions, 12 deletions
diff --git a/core/TagState.zig b/core/TagState.zig index 0a4d99a8..342c9812 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -232,12 +232,16 @@ pub fn dated(p: *Pardes, now_ns: u64) void { }; } -/// When a level next shows, for the loop's wake (Pardes.nextWake). +/// When a level next shows, for the loop's wake (Pardes.nextWake): a root +/// struck and not dated yet wants the next frame, whose advance dates it +/// (a pump settles its keys after its advance: a wake that waited for +/// the date would sleep until the next key, the level never shown). pub fn wake(p: *const Pardes) ?u64 { var soonest: ?u64 = null; for (p.views) |slot| if (slot) |v| { - const due = v.tag_state.due_ns; - if (due == asked or due == 0 or due <= p.clock.stepped_ns) continue; + var due = v.tag_state.due_ns; + if (due == asked) due = p.clock.stepped_ns + pardes.frame_ns; + if (due == 0 or due <= p.clock.stepped_ns) continue; soonest = if (soonest) |n| @min(n, due) else due; }; return soonest; @@ -761,3 +765,24 @@ test "C-w's level is window mode's, shown at once and kept while its keys move t try std.testing.expect(p.view().window_pick == null); try std.testing.expect(p.view().tag_state.root == null); } + +test "a root struck in a pump, after its advance, wakes the loop for the next frame, which dates it, then for its level" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 }); + defer p.deinit(); + _ = try p.setTestFile("one\n"); + while (p.nextEffect()) |_| {} + p.advance(5 * std.time.ns_per_s); + try std.testing.expect(p.nextWake() == null); + // The pump's order: its advance, then its keys (Pardes.pump, settle). + p.update(.{ .key = .{ .cp = ' ' } }); + const first = p.nextWake().?; + try std.testing.expectEqual(p.clock.stepped_ns + pardes.frame_ns, first); + p.advance(first); + const due = p.view().tag_state.due_ns; + try std.testing.expectEqual(first + 250 * std.time.ns_per_ms, due); + const second = p.nextWake().?; + try std.testing.expect(second >= due and second < due + pardes.frame_ns); + p.advance(second); + try std.testing.expect(shown(p, p.view())); + try std.testing.expect(p.nextWake() == null); +} diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig index e1f550e3..78503dec 100644 --- a/test/behaviour/keys.zig +++ b/test/behaviour/keys.zig @@ -375,11 +375,12 @@ test "keys: a PDF in normal mode keeps : (its tag and back), SPC (a leader, canc try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:normal ")); try s.keys(":"); try std.testing.expect(try s.cursor() == null); - // The leader shows its keys until one it has not. + // The leader shows its key cell in the tag at once (walk UI) until a + // key the PDF takes, which takes the leader away. try s.keys(" "); - try std.testing.expect(std.mem.indexOf(u8, try s.screen(), " SPC") != null); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), " ␣ ") != null); try s.keys("!"); - try std.testing.expect(std.mem.indexOf(u8, try s.screen(), " SPC") == null); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), " ␣ ") == null); try s.keys("/"); try std.testing.expect(try s.cursor() != null); try std.testing.expectEqual(n, try s.focused()); diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig index e615920d..a50cfb0e 100644 --- a/test/behaviour/modes.zig +++ b/test/behaviour/modes.zig @@ -118,11 +118,13 @@ fn threePanes(s: *Session) ![3]u32 { return .{ a, b, c }; } -/// The panes whose tag (`name Save`) is drawn in `lit`, the outline's colour. +/// The panes whose tag (`name `: the pane with the keyboard shows window +/// mode's head after its name, the others their own words) is drawn in +/// `lit`, the outline's colour. fn outlined(s: *Session, lit: []const u8, names: []const []const u8) ![]const u8 { var found: []const u8 = ""; for (names) |name| { - const x, const y = try s.where(s.at("{s} Save", .{name})); + const x, const y = try s.where(s.at("{s} ", .{name})); if (std.mem.eql(u8, lit, try s.bg(x, y))) found = s.at("{s}{s}", .{ found, name }); } return found; @@ -134,7 +136,7 @@ test "modes: Ctrl-w outlines a pane, h j k l move the outline, and Enter, Esc, : const a, const b, const c = try threePanes(&s); const names = &[_][]const u8{ "/a.txt", "/b.txt", "/c.txt" }; try s.keys("\x17"); - const x, const y = try s.where("/a.txt Save"); + const x, const y = try s.where("/a.txt "); const lit = try s.bg(x, y); try std.testing.expectEqualStrings("/a.txt", try outlined(&s, lit, names)); // Each pane's box shows its letter: the left column's is a. @@ -198,7 +200,7 @@ test "modes: in window mode d deletes the outlined pane, asking k or j between t try std.testing.expectEqualStrings("/mid", try outlined(&s, lit, names)); try s.keys("c"); try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{mid})), " collapsed ") == null); - try expectEqual(row_low, (try s.where("/low Save"))[1]); + try expectEqual(row_low, (try s.where("/low "))[1]); // d between two panes asks, as SPC d does; Esc takes it back, the // outline where it was. try s.keys("d"); @@ -210,7 +212,7 @@ test "modes: in window mode d deletes the outlined pane, asking k or j between t try s.keys("dj"); try std.testing.expect(!try listed(&s, mid)); try expectEqual(row_top, (try s.where("/test.txt Save"))[1]); - try expectEqual(row_mid, (try s.where("/low Save"))[1]); + try expectEqual(row_mid, (try s.where("/low "))[1]); try std.testing.expectEqualStrings("/low", try outlined(&s, lit, &.{ "/test.txt", "/low" })); // With one neighbour nothing is asked: d closes it, the outline on the // pane that grew. diff --git a/test/panes.zig b/test/panes.zig index ba3466fb..fd974b6c 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -2073,7 +2073,8 @@ const OutputTests = struct { try std.testing.expect(help.body.vsel.active); try std.testing.expect(help.body.vsel.row > 5); try std.testing.expect(help.body.cur_row != help.body.vsel.row); - for (" h?") |key| p.update(.{ .key = .{ .cp = key } }); + // `Help h`, the word (SPC h ? is Help in the tag now: walk UI). + try std.testing.expect(p.executeBuiltinLine(id, "Help h")); try std.testing.expectEqual(id, p.view().active); const content = help.file.?.content; try std.testing.expect(std.mem.startsWith(u8, content, "pardes builtins under SPC h\n")); |
