diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 10:08:22 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 10:16:33 -0300 |
| commit | 88c7a663468ab78ee3dbbc9726093dc4c3cf362f (patch) | |
| tree | 911c8328056e205159b2c2a6b492dfe2fd98da84 /core/Prompt.zig | |
| parent | 635829a5c17be4fd4bc30866e2b361c4ea2876e1 (diff) | |
| download | pardes-88c7a663468ab78ee3dbbc9726093dc4c3cf362f.tar.gz pardes-88c7a663468ab78ee3dbbc9726093dc4c3cf362f.zip | |
Prompt: a search's count keeps ` · N lines` after it, in the dim ink, and drops it with the hints (UX E7: E5 fix 8 reversed, the prototype's own `9/38 · 34 lines`); a wrap's `↻` is the count's, before it (`1/7 ↻ · 5 lines`, as n's echo says `1/3 ↻ · line 1`): THE CAUSE: Prompt.count wrote `3/7 · 5 lines ↻` all in the count's text ink, in the right block's count, which never drops (UX2: "`2/6 · 6 lines` in the count", D3 wants the count alone to stay); THE FIX: count returns where its ` · N lines` starts; head gives it a dim span and keeps it only while it and the hints fit beside the count with the right block's two gaps (Builder.right drops the hints alone, so head asks the same room for both, a cell or two sooner at most where the field already ends in blanks), else the count alone at the row's end; TEST FIRST: Prompt.zig "a search's count keeps ` · N lines` after it in the dim ink, and drops it with the hints where they do not fit beside it; a wrap's ↻ is the count's (UX E7, D3)" (200 and 52 columns, and a search from the last line round the end): fails on the base at Prompt.zig:1686 (no dim span), passes now; GOLDEN: fsearch regenerated (process-test -- --update fsearch), one row: the reader's tag row 16, cells 127-137 (` · 5 lines`) in the dim ink #79836f where they were the text ink #becfc4, its text the same; core-test 1086/1257 (171 skipped), process-test 1 of 147 failed before the golden (fsearch), 0 of 1 after
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Prompt.zig')
| -rw-r--r-- | core/Prompt.zig | 84 |
1 files changed, 72 insertions, 12 deletions
diff --git a/core/Prompt.zig b/core/Prompt.zig index 9dfe9ec2..ad2cfbed 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -1083,7 +1083,11 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head { } } // The count and the hints at the row's right end (UX D3). + const left = b.col(); const at = text.items.len; + // Where a search's ` · N lines` starts after its count: dim, and gone + // with the hints (UX E7). + var tail: ?usize = null; if (line.len > 0) { // A pattern that is no regex: why, in the err ink, in place of the // hints (UX D14), what is shown meanwhile dim; in the count's place, @@ -1095,11 +1099,23 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head { return .{ .text = text.items, .spans = spans.items, .cells = 1, .caret = caret }; } else if (behavior(pr.op) != null) { try pipeCount(p, arena, text, spans, pane, pr, line); - } else try count(arena, text, pane, pr); + } else tail = try count(arena, text, pane, pr); } if (pr.op == .command) try Command.count(p, arena, text); const hints = text.items.len; - try styled(arena, text, spans, info.get(pr.op).hint, .dim); + const hint = info.get(pr.op).hint; + if (tail) |t| { + // Both beside the count, or neither: as much room as the right + // block asks for its two gaps (Builder.right drops the hints alone). + const cells = File.displayWidth(p.settings.tab, std.mem.trimStart(u8, text.items[at..], " ")) + File.displayWidth(p.settings.tab, hint); + if (left + 2 + cells + 2 > b.width) { + text.shrinkRetainingCapacity(t); + try b.right(at, t); + return .{ .text = text.items, .spans = spans.items, .cells = 1, .caret = caret }; + } + try spans.append(arena, .{ .lo = @intCast(t), .hi = @intCast(hints), .style = .dim }); + } + try styled(arena, text, spans, hint, .dim); try b.right(at, hints); return .{ .text = text.items, .spans = spans.items, .cells = 1, .caret = caret }; } @@ -1111,24 +1127,34 @@ fn styled(arena: std.mem.Allocator, text: *std.ArrayList(u8), spans: *std.ArrayL } /// The prompt's count after its field: what it found (`4 selections in 6 -/// lines`, `keeps 3 of 9`, `3/7 · 5 lines`, `3/⋯` while its places are -/// found, `0`). -fn count(arena: std.mem.Allocator, text: *std.ArrayList(u8), pane: *Pane, pr: *const Prompt) !void { +/// lines`, `keeps 3 of 9`, `3/7 · 5 lines`, `1/7 ↻ · 5 lines`, `3/⋯` while +/// its places are found, `0`); where a search's ` · N lines` starts. +fn count(arena: std.mem.Allocator, text: *std.ArrayList(u8), pane: *Pane, pr: *const Prompt) !?usize { switch (pr.op) { .search, .search_back => { const set = &pane.places; - if (!set.shows(pane)) return; + if (!set.shows(pane)) return null; const hits = set.hits.items; - if (set.complete() and hits.len == 0) return text.appendSlice(arena, " 0"); + if (set.complete() and hits.len == 0) { + try text.appendSlice(arena, " 0"); + return null; + } try text.appendSlice(arena, " "); const at = if (set.current) |c| (if (c < hits.len) c else null) else null; if (at) |c| try text.print(arena, "{d}", .{c + 1}) else try text.appendSlice(arena, "–"); - if (!set.complete()) return text.appendSlice(arena, "/⋯"); - try text.print(arena, "/{d} · {d} line{s}", .{ hits.len, pr.lines, plural(pr.lines) }); + if (!set.complete()) { + try text.appendSlice(arena, "/⋯"); + return null; + } + try text.print(arena, "/{d}", .{hits.len}); // Round the end from where it began. - const c = at orelse return; - const origin = set.origin(pane); - if (if (pr.op == .search) hits[c].start < origin else hits[c].start > origin) try text.appendSlice(arena, " ↻"); + if (at) |c| { + const origin = set.origin(pane); + if (if (pr.op == .search) hits[c].start < origin else hits[c].start > origin) try text.appendSlice(arena, " ↻"); + } + const tail = text.items.len; + try text.print(arena, " · {d} line{s}", .{ pr.lines, plural(pr.lines) }); + return tail; }, .select, .split => if (pr.found == 0) try text.appendSlice(arena, " 0") @@ -1137,6 +1163,7 @@ fn count(arena: std.mem.Allocator, text: *std.ArrayList(u8), pane: *Pane, pr: *c .keep, .remove => try text.print(arena, " keeps {d} of {d}", .{ pr.found, pane.nsel_snap }), else => {}, } + return null; } /// A pipe prompt's count: `6 lines → 5 · exit 0`, `6 runs · 5 ok · 1 exit 2 @@ -1668,3 +1695,36 @@ test "Alt-Enter in / or s keeps the result as a list (SPEC §7.2): where jumps w try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind); try std.testing.expect(p.panes[p.view().active].?.query != null); } + +test "a search's count keeps ` · N lines` after it in the dim ink, and drops it with the hints where they do not fit beside it; a wrap's ↻ is the count's (UX E7, D3)" { + for ([_]u16{ 200, 52 }) |cols| { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = cols, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile(dirty); + pane.body.cur_row = 2; + pane.body.cur_col = 6; + typeKeys(p, "/dirty"); + const h = try head(p, p.scratch.allocator(), pane); + const lines = std.mem.indexOf(u8, h.text, " \u{b7} 5 lines"); + if (cols == 200) { + try std.testing.expect(has(h.text, "3/7 \u{b7} 5 lines \u{23ce} land")); + const dim = for (h.spans) |span| { + if (span.lo == lines.? and span.style == .dim) break span; + } else return error.TestUnexpectedResult; + try std.testing.expectEqualStrings(" \u{b7} 5 lines", h.text[dim.lo..dim.hi]); + } else { + // No room for the hints: the count alone, at the row's end. + try std.testing.expect(lines == null); + try std.testing.expect(std.mem.indexOf(u8, h.text, "\u{23ce} land") == null); + try std.testing.expect(std.mem.endsWith(u8, h.text, "3/7")); + } + } + // From the last line round the end: `↻` after the count, before its lines. + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile(dirty); + pane.body.cur_row = 7; + pane.body.cur_col = 6; + typeKeys(p, "/dirty"); + try std.testing.expect(has(try tagOf(p), "1/7 \u{21bb} \u{b7} 5 lines \u{23ce} land")); +} |
