diff options
| -rw-r--r-- | src/Messages.zig | 5 | ||||
| -rw-r--r-- | src/builtins.zig | 1 | ||||
| -rw-r--r-- | src/config.zig | 5 | ||||
| -rw-r--r-- | src/exec.zig | 2 | ||||
| -rw-r--r-- | src/panes.zig | 3 | ||||
| -rw-r--r-- | src/pardes.zig | 57 | ||||
| -rw-r--r-- | test/snapshots/delask.snap | 4 |
7 files changed, 74 insertions, 3 deletions
diff --git a/src/Messages.zig b/src/Messages.zig index 6785bd8a..cb52907a 100644 --- a/src/Messages.zig +++ b/src/Messages.zig @@ -582,7 +582,10 @@ pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void { for (pane.msg_older[0..pane.msg_older_len], 0..) |line, i| pane.notices.pushAt(.older, @intCast(i), line.slot); if (pane.msg_len > 0) pane.notices.pushAt(.message, 0, pane.msg_slot); if (id == p.active and p.leader_on) pane.notices.push(.leader); - if (pane.promptText()) |text| if (text.len > 0) pane.notices.push(.prompt); + // Del's question shows once its delay is up: answered before that, it + // was never there. + const del_waiting = pane.prompt == .del_side and pane.question_due_ns > p.now_ns; + if (pane.promptText()) |text| if (text.len > 0 and !del_waiting) pane.notices.push(.prompt); // A pane only has so many rows to give. When they do not all fit the // LAST ones survive, because the prompt is last and it is the one // carrying the cursor: a prompt you cannot see is a prompt you type diff --git a/src/builtins.zig b/src/builtins.zig index d2f215d7..4fb933b0 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1306,6 +1306,7 @@ pub const Del = struct { !c.pane.collapsed and c.pane.prompt == .none) { c.pane.prompt = .del_side; + c.pane.question_due_ns = exec.clockNow(c.p) + config.del_question_delay_ns; c.p.active = c.id; var rec: [32]u8 = undefined; pardes.ctlfs.events.notePath(c.p, "ask", std.fmt.bufPrint(&rec, "{d} del k j", .{c.pane.serial}) catch ""); diff --git a/src/config.zig b/src/config.zig index 2cb66c0a..e8016434 100644 --- a/src/config.zig +++ b/src/config.zig @@ -395,6 +395,11 @@ pub const search_submit: []const Chord = &.{.{ .cp = Key.enter }}; // Del from the keyboard on a pane with open panes both above and below it // asks which of them takes its rows. One key answers; any other keeps the pane. pub const del_question = "Del: give space to k above j below"; +// The question waits this long before it shows: SPC d j typed at speed +// never sees it, and a hand that pauses after SPC d (it pressed Del and +// nothing closed) gets it as a hint. Typed in one go the answer lands +// 100-250 ms after the d; a hesitation is longer than that. +pub const del_question_delay_ns: u64 = 400 * std.time.ns_per_ms; pub const del_above: []const Chord = &.{ .{ .cp = 'k' }, .{ .cp = Key.up } }; pub const del_below: []const Chord = &.{ .{ .cp = 'j' }, .{ .cp = Key.down } }; diff --git a/src/exec.zig b/src/exec.zig index 142dfef6..5b0eb204 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -622,7 +622,7 @@ const repl_quiet_ns: u64 = 100 * std.time.ns_per_ms; /// The host's clock now; core time (`now_ns`, `stepped_ns`) is as old as /// the last frame, seconds in an idle session. -fn clockNow(p: *Pardes) u64 { +pub fn clockNow(p: *Pardes) u64 { return if (p.host.vtable.now) |clock| clock(p.host.ctx) else p.now_ns; } diff --git a/src/panes.zig b/src/panes.zig index e0eb3fec..10e0d427 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -164,6 +164,9 @@ pub const Pane = struct { /// with its next output, the paste taken, or at `repl_enter_due_ns`. repl_enter: u8 = 0, repl_enter_due_ns: u64 = 0, + /// When Del's question (`del_side`) goes up on the notice band, on the + /// shell's clock (config.del_question_delay_ns after it was asked). + question_due_ns: u64 = 0, /// A question with its answers in it (`repl_choice`). question: [96]u8 = undefined, question_len: u8 = 0, 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 }); diff --git a/test/snapshots/delask.snap b/test/snapshots/delask.snap index 79ab527e..1e1ff72f 100644 --- a/test/snapshots/delask.snap +++ b/test/snapshots/delask.snap @@ -22,8 +22,10 @@ settle 100 key c-w k enter stable 400 5000 snap three -# asked, and nothing closes yet +# asked, and nothing closes yet; the question goes up on the band only after +# config.del_question_delay_ns (400 ms) with no answer, a hint key space d +settle 700 stable 400 5000 snap asked # Esc takes the question back: the pane stays |
