summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 05:58:33 -0300
committerGabriel Schneider <[email protected]>2026-11-25 05:58:33 -0300
commit1d440373e90516ace8e45e8e64f2e4ae5d4a4773 (patch)
tree2eb1247e10a143c37d4972d1d1f883a38e140a85 /core
parent99c70953a0c3b8e32cc5b61121c2b18e5ee68edd (diff)
downloadpardes-1d440373e90516ace8e45e8e64f2e4ae5d4a4773.tar.gz
pardes-1d440373e90516ace8e45e8e64f2e4ae5d4a4773.zip
TagState, Pick, Band: computed text breaks between its items only, a hanging indent under the spines, a rolled level three rows at most ending `+N ↓`, the picker's act row one row, a row too long cut with `…` (a path from the left) (walk UI polish P1, UX DESIGN.md D2): the rolled level was one long line wrapped by the tag's grapheme wrap, so a key fell apart from its label (`P`/`ClipPasteBefore`, `l ls`/`p…`, `D d`/`iagnostic end`) and its continuation rows started at the tag's first column under the box; the act row wrapped onto two (`Grep Rec`/`ent`); a band row was clipped at its step's edge; now (TagState.Builder) `keyCell` keeps each key cell's column and `row(indent)` starts a row of the head with a `│` under each key cell left of the indent (UX D5's spines through the tag's continuation rows; `// P2: the rule role`) and blanks up to it; the rolled level puts each child (`key label`) whole, a row's last child followed by the next row from the first child's column, three rows at most (a terminal's: the rows its own text takes, as before), the last one's last fitting child followed by a dim `+N ↓` (N the children not shown; the cells of it and of a struck key kept on the last row), its hints by the right block's rule on its last row (dropped where they do not fit); Pick.head's key cells are the builder's (its head's first spans, as every head's), its act row one row from two cells right of the last spine: the acts, `|`, the other sources, what does not fit dropped from the right (the sources first) and a dim `…` ending it (M-l, M-h reach them); Band.findSpines takes the key cells on whatever row they are (it wanted them on the tag's last row, so a picker's band had no spines and its steps started at the pane's edge: fsearch's list rows); Band.cutRow holds a row to its room with `…`: a path (its directory faint: Find's rows) cut from the left (`…r/Store.zig`), anything else from the right, its marks and faint bytes moved with it; TEST FIRST: TagState.zig "a rolled level breaks between its children only: ..." (SPC's level at 60 columns: three rows, the second and third `│ ` then a child, no row wider than the tag, every child shown whole, the rest counted in the last row's `+N ↓`; SPC h's on one row), Pick.zig "a picker's act row is one row under the spines ..." (60 columns: `│ │ Walk Look ` ... ` …`, a dim `…`), Band.zig "a row longer than its room is cut with `…` ..."; the SPC test reads a level of three rows at most; core-test 1066/1236 (170 skipped); process-test: 3 goldens regenerated and read: leader (the rolled level's second and third rows `│ ` from its first child's column, no child split, the hints at the last row's right end), find (`␣ f`'s hints at the row's end), fsearch (the list picker's act row one row ending `Panes …`, its band rows under spines from two cells right of the last, the body a row up); a user met the split words at every width under ~160 columns
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core')
-rw-r--r--core/Band.zig63
-rw-r--r--core/Pick.zig103
-rw-r--r--core/TagState.zig139
3 files changed, 227 insertions, 78 deletions
diff --git a/core/Band.zig b/core/Band.zig
index 024b6be4..0d4891aa 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -394,20 +394,16 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi
band.nsteps = kept;
}
-/// The display columns of the head's key cells, when they are all on the
-/// tag's last row (the spines hang from there).
+/// The display columns of the head's key cells: a spine hangs under each,
+/// through the tag's rows under them and the band's (UX D5).
fn findSpines(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !void {
const h = (try TagState.head(p, arena, pane)) orelse return;
const whole = try tagline.tagText(p, arena, pane);
const shown = try tagline.wrapTag(p.settings.tab, arena, whole, tagline.tagWidth(p, id));
const lead = whole.len - h.text.len;
- const last = shown.rows() -| 1;
for (h.spans[0..h.cells]) |span| {
const at = modal.positionAt(shown.text, shown.fromReal(lead + span.lo));
- if (at.row != last or band.nspines == max_spines) {
- band.nspines = 0;
- return;
- }
+ if (band.nspines == max_spines) return;
band.spines[band.nspines] = @intCast(File.rawDisplayCol(p.settings.tab, modal.lineSlice(shown.text, at.row), at.col));
band.nspines += 1;
}
@@ -484,16 +480,46 @@ pub fn line(band: *const Band, arena: std.mem.Allocator, tab: u16, y: u16) !Line
const lead: []const u8 = if (step.doc) "" else if (row.on) "▶ " else if (row.mark) "• " else " ";
try text.appendSlice(arena, lead);
col += @intCast(File.displayWidth(tab, lead));
- try parts.append(arena, .{ .col = col, .width = per -| @as(u16, @intCast(File.displayWidth(tab, lead))), .row = row });
const room = per -| @as(u16, @intCast(File.displayWidth(tab, lead)));
- const cut = File.byteAtDisplay(tab, row.text, room);
- try text.appendSlice(arena, row.text[0..cut]);
- col += @intCast(File.displayWidth(tab, row.text[0..cut]));
+ const fit = try cutRow(arena, tab, row, room);
+ try parts.append(arena, .{ .col = col, .width = room, .row = fit });
+ try text.appendSlice(arena, fit.text);
+ col += @intCast(File.displayWidth(tab, fit.text));
}
}
return .{ .text = text.items, .parts = parts.items };
}
+/// Row `row` held to `room` cells (UX D2): a longer one cut with `…`, a
+/// path (its directory faint: Find's rows) from the left
+/// (`…core/Store.zig`), anything else from the right; its marks and faint
+/// bytes moved with its text.
+fn cutRow(arena: std.mem.Allocator, tab: u16, row: Row, room: u16) !Row {
+ if (File.displayWidth(tab, row.text) <= room) return row;
+ var fit = row;
+ var marks: std.ArrayList(u16) = .empty;
+ if (row.faint > 0 and row.pre == 0 and room > 1) {
+ var from = row.text.len;
+ while (from > 0) {
+ const before = modal.prevGrapheme(row.text, from);
+ if (File.displayWidth(tab, row.text[before..]) > room - 1) break;
+ from = before;
+ }
+ fit.text = try std.mem.concat(arena, u8, &.{ "…", row.text[from..] });
+ for (row.marks) |m| if (m >= from) try marks.append(arena, @intCast(m - from + "…".len));
+ fit.faint = @intCast(if (row.faint > from) row.faint - from + "…".len else "…".len);
+ } else {
+ const cut = File.byteAtDisplay(tab, row.text, room -| 1);
+ fit.text = try std.mem.concat(arena, u8, &.{ row.text[0..cut], if (room > 0) "…" else "" });
+ for (row.marks) |m| if (m < cut) try marks.append(arena, m);
+ fit.key = @intCast(@min(row.key, cut));
+ fit.pre = @intCast(@min(row.pre, cut));
+ fit.faint = @intCast(@min(row.faint, cut -| fit.pre));
+ }
+ fit.marks = marks.items;
+ return fit;
+}
+
/// The word under column `col` of band row `y` of pane `id`, at the
/// tagline's pitch: what B2 executes and B3 looks at.
pub fn wordAt(p: *Pardes, arena: std.mem.Allocator, id: usize, y: u16, col: u16) !?[]const u8 {
@@ -518,6 +544,21 @@ fn layerRow(arena: std.mem.Allocator, layer: *const pardes.Layer, row: usize) ![
return out.items;
}
+test "a row longer than its room is cut with `…`: a path from the left, anything else from the right, its marks and faint bytes moved with it" {
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ const a = arena.allocator();
+ const path = try cutRow(a, 8, .{ .text = "core/deep/dir/Store.zig", .faint = 14, .marks = &.{ 0, 14, 15 } }, 12);
+ try std.testing.expectEqualStrings("…r/Store.zig", path.text);
+ try std.testing.expectEqual(@as(u16, 5), path.faint);
+ try std.testing.expectEqualSlices(u16, &.{ 5, 6 }, path.marks);
+ const other = try cutRow(a, 8, .{ .text = "a.zig:3:1: hello world", .pre = 9, .marks = &.{ 10, 20 } }, 12);
+ try std.testing.expectEqualStrings("a.zig:3:1: …", other.text);
+ try std.testing.expectEqualSlices(u16, &.{10}, other.marks);
+ const fits = try cutRow(a, 8, .{ .text = "short" }, 12);
+ try std.testing.expectEqualStrings("short", fits.text);
+}
+
test "SPC Down unrolls the level into a band under the tag's text, the body pushed down and never drawn over; Up on its first row rolls it up" {
const Key = pardes.Key;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
diff --git a/core/Pick.zig b/core/Pick.zig
index 8fcc5945..52976f15 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -565,17 +565,8 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
const s = &p.view().tag_state;
var b = try TagState.Builder.of(p, arena, pane);
const text = &b.text;
- const spans = &b.spans;
- var cells: [4][2]u32 = undefined;
- var ncells: usize = 0;
// SPC's cell, then its keys': `␣ f`.
- if (pk.keys.len > 0) for (0..pk.keys.len + 1) |k| {
- const name = if (k == 0) "␣" else bindings.keyName(pk.keys.slice()[k - 1]);
- cells[ncells] = .{ @intCast(text.items.len), @intCast(text.items.len + name.len) };
- ncells += 1;
- try text.appendSlice(arena, name);
- try text.append(arena, ' ');
- };
+ if (pk.keys.len > 0) try b.keyCells(.leader, pk.keys.slice());
try text.appendSlice(arena, pk.word.slice());
try text.append(arena, ' ');
for (pk.refined[0..pk.nrefined]) |r| try text.print(arena, "{s} | ", .{r.query.slice()});
@@ -594,38 +585,43 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
const hints = text.items.len;
try b.styled("⏎ wear it · esc", .dim);
try b.right(counted, hints);
- for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key });
- return .{ .text = text.items, .spans = spans.items, .cells = @intCast(ncells), .caret = caret };
+ var h = b.done();
+ h.caret = caret;
+ return h;
}
try b.right(counted, text.items.len);
- // The second row: the spines go on through it from the key cells,
- // then the other sources' words, each switching to it.
- try text.append(arena, '\n');
- const prefix = try pardes.tagline.prefixIn(p, arena, pane);
- const width = pardes.tagline.tagWidth(p, panes.paneIdOf(p, pane) orelse 0);
- const lead = File.displayWidth(p.settings.tab, prefix) % @max(1, width);
- var col: usize = 0;
- for (cells[0..ncells]) |c| {
- const at = lead + File.displayWidth(p.settings.tab, text.items[0..c[0]]);
- while (col < at) : (col += 1) try text.append(arena, ' ');
- try spans.append(arena, .{ .lo = @intCast(text.items.len), .hi = @intCast(text.items.len + "│".len), .style = .key });
- try text.appendSlice(arena, "│");
- col += 1;
- }
- const nspines: u8 = @intCast(spans.items.len);
- try text.appendSlice(arena, if (ncells == 0) "" else " ");
- for (acts) |act| if (offered(pk, act)) try text.print(arena, "{s} ", .{act.word});
- try text.appendSlice(arena, "|");
- var first = false;
- inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes) {
- if (src != pk.source) {
- if (!first) try text.append(arena, ' ');
- first = false;
- try text.appendSlice(arena, words.get(src).word);
- }
+ // The second row, one row (UX D2): under the spines from the key
+ // cells, from two cells right of the last, the acts, `|`, the other
+ // sources' words, each switching to it; what does not fit is dropped
+ // from the right (the sources first) and the row ends in a dim `…`
+ // (M-l and M-h reach them all).
+ try b.row(if (b.ncols > 0) b.cols[b.ncols - 1] + 2 else 0);
+ var offer: [acts.len + 1 + std.enums.values(Source).len][]const u8 = undefined;
+ var nw: usize = 0;
+ for (acts) |act| if (offered(pk, act)) {
+ offer[nw] = act.word;
+ nw += 1;
+ };
+ offer[nw] = "|";
+ nw += 1;
+ inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != pk.source) {
+ offer[nw] = words.get(src).word;
+ nw += 1;
};
- for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key });
- return .{ .text = text.items, .spans = spans.items, .cells = nspines, .caret = caret };
+ for (offer[0..nw], 0..) |word, i| {
+ const gap: usize = @intFromBool(i > 0);
+ const rest: usize = if (i + 1 < nw) 2 else 0;
+ if (b.col() + gap + File.displayWidth(p.settings.tab, word) + rest > b.width) {
+ try b.put(if (gap > 0) " " else "");
+ try b.styled("…", .dim);
+ break;
+ }
+ try b.put(if (gap > 0) " " else "");
+ try b.put(word);
+ }
+ var h = b.done();
+ h.caret = caret;
+ return h;
}
/// The band's rows: as many as the list will show, eleven at most, from
@@ -1553,6 +1549,35 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the
try std.testing.expectEqualStrings("pick", pk.query.slice());
}
+test "a picker's act row is one row under the spines, two cells right of the last: what does not fit dropped from the right, the sources first, a dim `…` ending it" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 40 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n");
+ defer p.gpa.free(a_path);
+ _ = try p.setTestFile("held\n");
+ const asker = p.view().active;
+ Trail.keep(p.panes[asker].?);
+ p.stream.engine = .walk;
+ open(p, asker, .find, "", "", "");
+ const reader = p.paneBySerial(live(p).?.landing).?;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const tag = try tagOf(p, a, reader);
+ var rows = std.mem.splitScalar(u8, tag, '\n');
+ try std.testing.expect(std.mem.startsWith(u8, rows.next().?, "␣ f Find "));
+ const acts_row = rows.next().?;
+ try std.testing.expect(rows.next() == null);
+ try std.testing.expect(std.mem.startsWith(u8, acts_row, "│ │ Walk Look "));
+ try std.testing.expect(std.mem.endsWith(u8, acts_row, " …"));
+ try std.testing.expect(File.displayWidth(p.settings.tab, acts_row) <= pardes.tagline.tagWidth(p, reader));
+ const h = (try head(p, a, p.panes[reader].?)).?;
+ try std.testing.expect(h.spans[h.spans.len - 1].style == .dim);
+}
+
test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and Backspace undoes it, M-h switches source keeping the query" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
defer p.deinit();
diff --git a/core/TagState.zig b/core/TagState.zig
index d70edf47..18fd5fac 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -478,6 +478,9 @@ pub const Builder = struct {
width: usize = 0,
lead: usize = 0,
tab: u16 = 8,
+ /// Each key cell's column, which a spine hangs under (UX D5).
+ cols: [Band.max_spines]u16 = undefined,
+ ncols: u8 = 0,
/// A head for pane `pane`'s tag, out of rest in the live view.
pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !Builder {
@@ -517,10 +520,10 @@ pub const Builder = struct {
h -= lead_c;
while (h > count and b.text.items[h - 1] == ' ') : (h -= 1) b.cut(h - 1, h);
const items = b.text.items;
- const row = if (std.mem.lastIndexOfScalar(u8, items[0..count], '\n')) |nl| nl + 1 else 0;
- const left = panes.File.displayWidth(b.tab, items[row..count]) + if (row == 0) b.lead else 0;
+ const start = if (std.mem.lastIndexOfScalar(u8, items[0..count], '\n')) |nl| nl + 1 else 0;
+ const left = panes.File.displayWidth(b.tab, items[start..count]) + if (start == 0) b.lead else 0;
var trail: usize = 0;
- while (trail < count - row and items[count - 1 - trail] == ' ') trail += 1;
+ while (trail < count - start and items[count - 1 - trail] == ' ') trail += 1;
const cw = panes.File.displayWidth(b.tab, items[count..h]);
var hw = panes.File.displayWidth(b.tab, items[h..]);
const between: usize = if (cw > 0) 2 else 0;
@@ -566,13 +569,34 @@ pub const Builder = struct {
}
/// The keys typed as 2-cell key cells: the root's, then each key.
pub fn keyCells(b: *Builder, root: Root, path: []const u8) !void {
- try b.styled(bindings.info.get(root).cell, .key);
+ try b.keyCell(bindings.info.get(root).cell);
+ for (path) |k| try b.keyCell(if (k == ' ') "␣" else bindings.keyName(k));
+ b.cells = @intCast(b.spans.items.len);
+ }
+
+ /// One key cell, its column kept for its spine, and the blank after it.
+ pub fn keyCell(b: *Builder, name: []const u8) !void {
+ if (b.ncols < b.cols.len) {
+ b.cols[b.ncols] = @intCast(b.col());
+ b.ncols += 1;
+ }
+ try b.styled(name, .key);
try b.put(" ");
- for (path) |k| {
- try b.styled(if (k == ' ') "␣" else bindings.keyName(k), .key);
- try b.put(" ");
+ }
+
+ /// A row more of the head (UX D2): the spines on through it under each
+ /// key cell left of `indent` (UX D5), then blanks up to `indent`, a
+ /// hanging indent where the row's words start.
+ pub fn row(b: *Builder, indent: usize) !void {
+ try b.text.append(b.arena, '\n');
+ var at: usize = 0;
+ for (b.cols[0..b.ncols]) |c| {
+ if (c >= indent) break;
+ try b.text.appendNTimes(b.arena, ' ', c - at);
+ try b.styled("│", .key); // P2: the rule role (UX D4)
+ at = c + 1;
}
- b.cells = @intCast(b.spans.items.len);
+ try b.text.appendNTimes(b.arena, ' ', indent -| at);
}
pub fn done(b: *const Builder) Head {
return .{ .text = b.text.items, .spans = b.spans.items, .cells = b.cells };
@@ -670,31 +694,35 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
return b.done();
}
try b.styled("▸", .key);
- // The rolled level wraps to three rows at most (SPEC §3.6): what does
- // not fit is `…`, and `↓` unrolls it whole. A terminal's to the rows its
- // own text takes: its pty is its body, and a which-key that took a row
- // would resize the program under it at every SPC. Every cell is
- // counted: the prefix, each child with its separator and a group's
- // `…`, the ` …` after a child that is not the last, a struck key, the
- // hint (left out, a terminal's tag took a row more at some widths).
- const hint = " ↓ unroll · ? help";
- const more = " …";
- const prefix = try tagline.prefixIn(p, arena, pane);
+ // The rolled level breaks between its children only (UX D2), each row
+ // after the first from the first child's column, its spines on through
+ // it; three rows at most, the last ending `+N ↓` (N the children not
+ // shown, `↓` unrolls them) when they do not fit. A terminal's to the
+ // rows its own text takes: its pty is its body, and a which-key that
+ // took a row would resize the program under it at every SPC.
const tab = p.settings.tab;
const most: usize = if (pane.isTerminal()) @import("layout.zig").wantedTagRows(p, id) else 3;
- const struck: usize = if (s.miss != 0) 1 + panes.File.displayWidth(tab, bindings.keyName(s.miss)) else 0;
- const room = most * tagline.tagWidth(p, id) -| panes.File.displayWidth(tab, prefix) -| panes.File.displayWidth(tab, hint) -| struck;
var children: [bindings.max_children]bindings.Child = undefined;
const level = bindings.level(p, cur.root, cur.path, &children);
const used = s.used[node.group];
- var width = panes.File.displayWidth(tab, b.text.items);
+ const indent = b.col() + 1;
+ // A struck key goes after the children: the last row keeps its cells.
+ const struck: usize = if (s.miss != 0) 1 + panes.File.displayWidth(tab, bindings.keyName(s.miss)) else 0;
+ var rows: usize = 1;
for (level, 0..) |c, i| {
- width += @as(usize, if (i == 0) 1 else 2) + panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, c.label) + @intFromBool(c.group);
- if (width + @as(usize, if (i + 1 < level.len) panes.File.displayWidth(tab, more) else 0) > room) {
- try b.put(more);
+ const w = panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, c.label) + @intFromBool(c.group or c.more);
+ var gap: usize = if (i == 0) 1 else 2;
+ if (b.col() + gap + w + more(level.len - i - 1, rows == most) + (if (rows == most) struck else 0) > b.width and rows < most and b.col() > indent) {
+ try b.row(indent);
+ rows += 1;
+ gap = 0;
+ }
+ if (b.col() + gap + w + more(level.len - i - 1, rows == most) + (if (rows == most) struck else 0) > b.width) {
+ try b.put(if (gap == 0) "" else " ");
+ try b.styled(try std.fmt.allocPrint(arena, "+{d} ↓", .{level.len - i}), .dim);
break;
}
- try b.put(if (i == 0) " " else " ");
+ try b.put(if (gap == 0) "" else if (gap == 1) " " else " ");
const lo: u32 = @intCast(b.text.items.len);
try b.styled(bindings.keyName(c.key), .key);
try b.put(" ");
@@ -705,13 +733,24 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
if (c.key == used) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .under });
}
if (s.miss != 0) {
- try b.put(" ");
+ if (b.col() + struck > b.width and rows < most) try b.row(indent) else try b.put(" ");
try b.styled(bindings.keyName(s.miss), .strike);
}
- try b.put(hint);
+ // Its hints on its last row, by the right block's rule (UX D3).
+ const hints = b.text.items.len;
+ try b.styled("↓ unroll · ? help", .dim);
+ try b.right(hints, hints);
return b.done();
}
+/// The cells `+N ↓` takes after a child on a rolled level's last row, with
+/// `n` children after it.
+fn more(n: usize, last: bool) usize {
+ if (n == 0 or !last) return 0;
+ // Two blanks, `+`, N, a blank, `↓`.
+ return 5 + std.fmt.count("{d}", .{n});
+}
+
fn testTag(p: *Pardes, arena: std.mem.Allocator) ![]const u8 {
return tagline.tagText(p, arena, p.panes[p.view().active].?);
}
@@ -748,7 +787,7 @@ test "SPC changes nothing in the tag until its level shows 250 ms on, its keys o
const level = try testTag(p, a);
try std.testing.expect(std.mem.indexOf(u8, level, "␣ ▸ b buffer…") != null);
try std.testing.expect(std.mem.indexOf(u8, level, "l lsp…") != null);
- try std.testing.expect(std.mem.endsWith(u8, level, "↓ unroll · ? help"));
+ try std.testing.expect(std.mem.count(u8, level, "\n") < 3);
// Down a level: its keys, its children.
p.update(.{ .key = .{ .cp = 'l' } });
try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "␣ l ▸ a CodeAction b Callstack"));
@@ -836,6 +875,50 @@ test "the right block: the count `cursor/matches` at the row's right end, fixed
try std.testing.expectEqualStrings("␣ SPC", firstRow(try testTag(narrow, a)));
}
+test "a rolled level breaks between its children only: the rows after the first from its first child's column under the spines, three at most, the last ending `+N ↓`" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 30 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const tab = p.settings.tab;
+ const width = tagline.tagWidth(p, p.view().active);
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ const tag = try testTag(p, a);
+ var rows: [8][]const u8 = undefined;
+ var n: usize = 0;
+ var split = std.mem.splitScalar(u8, tag, '\n');
+ while (split.next()) |row| : (n += 1) rows[n] = row;
+ try std.testing.expectEqual(@as(usize, 3), n);
+ try std.testing.expect(std.mem.startsWith(u8, rows[0], "␣ ▸ b buffer… "));
+ // Each row after the first: the spine under `␣`, then from the first
+ // child's column; no row wider than the tag.
+ for (rows[1..n]) |row| try std.testing.expect(std.mem.startsWith(u8, row, "│ ") and row["│ ".len] != ' ');
+ for (rows[0..n]) |row| try std.testing.expect(panes.File.displayWidth(tab, row) <= width);
+ // Every child shown is whole on one row; the ones not shown are counted.
+ var children: [bindings.max_children]bindings.Child = undefined;
+ const level = bindings.level(p, .leader, "", &children);
+ var whole: usize = 0;
+ for (level) |c| {
+ const item = try std.fmt.allocPrint(a, "{s} {s}", .{ bindings.keyName(c.key), c.label });
+ for (rows[0..n]) |row| {
+ if (std.mem.indexOf(u8, row, item) != null) break;
+ } else continue;
+ whole += 1;
+ }
+ try std.testing.expect(whole > 0 and whole < level.len);
+ try std.testing.expect(std.mem.endsWith(u8, rows[n - 1], try std.fmt.allocPrint(a, "+{d} ↓", .{level.len - whole})));
+ // A level that fits takes one row; its hints at its end where the row
+ // has room for them, else none.
+ p.update(.{ .key = .{ .cp = 'h' } });
+ const help = try testTag(p, a);
+ try std.testing.expect(std.mem.indexOfScalar(u8, help, '\n') == null);
+ try std.testing.expect(std.mem.startsWith(u8, help, "␣ h ▸ b Build ") and std.mem.endsWith(u8, help, " t Tutor"));
+}
+
test "a leaf run from a level is remembered: underlined there, and said on the line under it" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 });
defer p.deinit();