summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 13:44:56 -0300
committerGabriel Schneider <[email protected]>2026-10-24 15:41:50 -0300
commit578710b72755503ef2ef40a0ae301e608af3e3af (patch)
tree9d7c3574fcff5bbe7f975c802425446b6cc41065 /src/pardes.zig
parentb32447e0b265f25ad7807760956bedf8cf42664d (diff)
downloadpardes-578710b72755503ef2ef40a0ae301e608af3e3af.tar.gz
pardes-578710b72755503ef2ef40a0ae301e608af3e3af.zip
The Del question is a hint: shown on the notice band only after 400 ms of waiting for k or j
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index f4158808..3c5cf6a7 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -7674,6 +7674,12 @@ pub const Pardes = struct {
const wait = Messages.messageWake(p, pane) orelse continue;
frames = if (frames) |soonest| @min(soonest, wait) else wait;
};
+ // Del's question goes up at the end of its delay: a frame then, and
+ // none after (stepped time has reached it).
+ for (p.panes) |slot| if (slot) |pane| if (pane.prompt == .del_side and pane.question_due_ns > p.stepped_ns) {
+ const wait = @max(1, (pane.question_due_ns - p.stepped_ns + animation.frame_ns - 1) / animation.frame_ns);
+ frames = if (frames) |soonest| @min(soonest, wait) else wait;
+ };
// A paste's Enter waiting on its REPL goes at the end of its wait,
// a time on the clock: the frames from `stepped_ns` that reach it.
for (p.panes) |slot| if (slot) |pane| if (pane.repl_enter > 0) {
@@ -8185,6 +8191,7 @@ test "Del from a key asks which neighbour takes the rows; nothing else asks" {
p.update(.{ .key = .{ .cp = 'd' } });
try std.testing.expect(p.panes[mid] != null);
try std.testing.expectEqual(Pane.Prompt.del_side, p.panes[mid].?.prompt);
+ p.now_ns = p.panes[mid].?.question_due_ns; // shown once its delay is up
_ = try p.render(frame.allocator());
try std.testing.expectEqual(Pane.Notices.Kind.prompt, p.panes[mid].?.notices.kinds[p.panes[mid].?.notices.len - 1]);
try std.testing.expectEqualStrings(config.del_question, p.panes[mid].?.promptText().?);
@@ -8622,6 +8629,56 @@ test "window mode moves an outline and focuses it on Enter, Esc or a label" {
try std.testing.expectEqualStrings("a", box.text[0..box.len]);
}
+test "the Del question shows only once its delay is up: a quick SPC d j never sees it" {
+ if (platform == .web) return;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 });
+ defer p.deinit();
+ p.settings.placement = .pardes;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const top = p.active;
+ p.newScratchBelow(top);
+ const mid = p.active;
+ p.newScratchBelow(mid);
+ p.sync();
+ p.active = mid;
+ p.now_ns = 5 * std.time.ns_per_s;
+ p.stepped_ns = p.now_ns;
+ const asked_at = p.now_ns;
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.update(.{ .key = .{ .cp = 'd' } });
+ const pane = p.panes[mid].?;
+ try std.testing.expectEqual(Pane.Prompt.del_side, pane.prompt);
+ try std.testing.expectEqual(asked_at + config.del_question_delay_ns, pane.question_due_ns);
+ // Asked, and nothing on the band yet.
+ _ = try p.render(frame.allocator());
+ for (pane.notices.kinds[0..pane.notices.len]) |kind| try std.testing.expect(kind != .prompt);
+ // The loop wakes for it, at the end of the delay and not before.
+ const wake = p.nextWake().?;
+ try std.testing.expect(wake >= pane.question_due_ns and wake < pane.question_due_ns + animation.frame_ns);
+ p.now_ns = pane.question_due_ns - 1;
+ _ = try p.render(frame.allocator());
+ for (pane.notices.kinds[0..pane.notices.len]) |kind| try std.testing.expect(kind != .prompt);
+ // Its time come, it is the band's last line; stepped past it, nothing
+ // more to wake for.
+ p.now_ns = wake;
+ p.stepped_ns = wake;
+ _ = try p.render(frame.allocator());
+ try std.testing.expectEqual(Pane.Notices.Kind.prompt, pane.notices.kinds[pane.notices.len - 1]);
+ try std.testing.expect(p.nextWake() == null);
+ // A key answers it either way, shown or not: Esc keeps the pane.
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(Pane.Prompt.none, pane.prompt);
+ try std.testing.expect(p.nextWake() == null);
+ // A fast SPC d j: closed before the band ever showed the question.
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.update(.{ .key = .{ .cp = 'd' } });
+ _ = try p.render(frame.allocator());
+ for (pane.notices.kinds[0..pane.notices.len]) |kind| try std.testing.expect(kind != .prompt);
+ p.update(.{ .key = .{ .cp = 'j' } });
+ try std.testing.expect(p.panes[mid] == null);
+}
+
test "window mode d deletes the outlined pane and asks k or j, c collapses it, and the mode stays" {
if (platform == .web) return;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 40 });