summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 21:28:54 -0300
committerGabriel Schneider <[email protected]>2026-11-24 21:40:53 -0300
commit9f4109bceefbfc3e63eaf510eb7d05603e09db9c (patch)
tree6ee3a51a29da114ae9eb0d14891860881cc54f5c /core
parente64bd853c33bce38f91c9103c0afceb690333585 (diff)
downloadpardes-9f4109bceefbfc3e63eaf510eb7d05603e09db9c.tar.gz
pardes-9f4109bceefbfc3e63eaf510eb7d05603e09db9c.zip
TagState, Core, Band, process-test: a tag out of rest keeps its rows at rest, a rolled level counts every cell it adds, a doc's paragraphs are rows, and the +Help cases use the word (fixes on top of items 2-5 of line A, uqopxwqz vnqmzpqs kquzozvs okqtwzll moosvmpn, frozen): process-test's six failures on moosvmpn: TAGNAV (row 6's `$` gone after `c-w l enter`, `c-b`) and LOOKPANES (`@alpha` off row 6 after `space w h`, on the parallel pass only): RUN: a screen dumped before each click: lookpanes' shell tag `/tmp/.../cwd C-w …` on ONE row where its own text takes two, the shell's rows moved up one; tagnav's shell pty resized twice by `c-w h enter` from its focused tag (bash's redraw lost its prompt mark); THE CAUSE: Core.zig sync gave a tag out of rest the rows its head takes, and a root's key cell (` C-w …`, ` ␣ …`, before its level shows 250 ms on) is shorter than the tag's own text: the body moved up and back down, a terminal's pty resized under its program (moosvmpn bounded a terminal's rolled level from above only); and TagState.head's room left out the ` …` past the last child that fits, each group's `…` and a struck key (at 100 columns C-w's level took 97 of a terminal's 96 cells, three rows for its two); THE FIX: sync: out of rest (hostOf), a tag keeps the rows its own text takes (layout.wantedTagRows), at least, and a terminal's exactly; tag_top saturates (a head of fewer lines than the tag's rows overflowed `lines - tag_rows` when the tag had the keyboard: a panic the first fix met in tagnav); head counts every cell (exact separators, `…`s, the struck key) and the child whose ` …` would not fit stops the level; DECIDED (SPEC §3.6's give-way order): a text pane's rolled level may wrap its tag to three rows (the first give-way, the §3.7 mockup's two rows), never fewer rows than at rest; a terminal's, exactly its rows at rest; a user hit both: every SPC or C-w in a pane whose tag takes two rows or more moved its body up for 250 ms, and in a terminal resized its program twice; THE BAND (seen in ttyhelp's new golden): a doc's paragraphs, a line each in builtins.Doc.text, were drawn as one row with a `�` for each newline (Band.wrap): each now starts a row; FIND, LEADER, BUILTINS, TTYHELP: `SPC ?` and `?` down a level are Help in the tag now (SPEC §4.5), so the cases that test the +Help index run the word (`Help` from the workspace tag, `Help h`, `Help t`, `Help c`, `Help l` swept with B2 on a line of their file, tty_boot.zig sweepHelp); ttyhelp's `SPC ?` shows the new Help in the focused pane's tag, `tutor` typed into its field; the snapshots taken after SPC wait for its level (the quiet screen of the parallel pass came back before the 250 ms frame: a golden that depended on the pass); leader presses Esc after its struck key (the level stays, A's ruling); GOLDENS, every changed row: find: `group` the rolled SPC f level in the tag over two rows (the hint cut by the cell, acme's wrap), the body a row down, the `SPC f` chip gone; `armed` the tag back at rest; ttyhelp: `leaderworks` the +Help's tag `^ ... Help tutor 1/133`, its band (the row, the doc step, no `�`) pushing its body four rows down; builtins: notes.txt's first line `Help c Help h`; the +Help for SPC h with Keys (SPC h k, item 5) and its documentation, every row under it six down, the +Look search on line 224 for 220, Tutor's row 30 for 24; leader: `spc`, `spc-h`, `unmapped` the rolled levels (SPC's over three rows, `x` struck), cmds.txt's line of five words, the Help announcement chip, the Keys rows, the tutor a row lower under the longer +Help; TESTS FIRST: TagState.zig "a rolled level fits its rows at every width..." (failed: 4 rows), "a terminal's rolled level keeps its tag rows at every width, C-w's as SPC's..." (shell-test; failed: expected 2, found 3), "a tag out of rest keeps its rows at rest at least..." (failed: expected 2, found 1; then the integer overflow at Core.zig:2047 with the keyboard in the tag), Band.zig "a doc's paragraphs are rows of their own..." (failed: a newline in a row)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core')
-rw-r--r--core/Band.zig55
-rw-r--r--core/Core.zig11
-rw-r--r--core/TagState.zig97
3 files changed, 141 insertions, 22 deletions
diff --git a/core/Band.zig b/core/Band.zig
index 9fa204ee..03cdbbda 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -328,24 +328,31 @@ fn findSpines(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id
}
/// `rows` wrapped at `width` display columns, word by word, `height` rows
-/// at most: a doc's paragraphs.
+/// at most: a doc's paragraphs, a line each in its text (builtins.Doc),
+/// each starting a row (a newline drawn in a row was a `�`).
fn wrap(arena: std.mem.Allocator, tab: u16, rows: []const Row, width: u16, max: u16) ![]const Row {
var out: std.ArrayList(Row) = .empty;
- for (rows) |row| {
- if (File.displayWidth(tab, row.text) <= width) {
- try out.append(arena, row);
- } else {
- var rest = row.text;
- while (rest.len > 0 and out.items.len < max) {
- var cut = File.byteAtDisplay(tab, rest, width);
- if (cut < rest.len) {
- if (std.mem.lastIndexOfScalar(u8, rest[0..cut], ' ')) |space| {
- if (space > 0) cut = space;
+ for (rows) |whole| {
+ var paragraphs = std.mem.splitScalar(u8, whole.text, '\n');
+ var row = whole;
+ while (paragraphs.next()) |text| : (row = .{ .text = "" }) {
+ if (out.items.len >= max) break;
+ row.text = text;
+ if (File.displayWidth(tab, row.text) <= width) {
+ try out.append(arena, row);
+ } else {
+ var rest = row.text;
+ while (rest.len > 0 and out.items.len < max) {
+ var cut = File.byteAtDisplay(tab, rest, width);
+ if (cut < rest.len) {
+ if (std.mem.lastIndexOfScalar(u8, rest[0..cut], ' ')) |space| {
+ if (space > 0) cut = space;
+ }
}
+ if (cut == 0) cut = modal.nextGrapheme(rest, 0);
+ try out.append(arena, .{ .text = std.mem.trimEnd(u8, rest[0..cut], " ") });
+ rest = std.mem.trimStart(u8, rest[cut..], " ");
}
- if (cut == 0) cut = modal.nextGrapheme(rest, 0);
- try out.append(arena, .{ .text = std.mem.trimEnd(u8, rest[0..cut], " ") });
- rest = std.mem.trimStart(u8, rest[cut..], " ");
}
}
if (out.items.len >= max) break;
@@ -540,3 +547,23 @@ test "the band's words are read-only text: B2 runs one, the tag back at rest" {
try std.testing.expect(p.settings.wrap != wrapped);
try std.testing.expect(p.view().prefix == .none and !p.view().tag_state.unrolled);
}
+
+test "a doc's paragraphs are rows of their own: no newline in a band's row" {
+ const Key = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ const id = p.view().active;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ // SPC b b is Panes, whose documentation has three paragraphs.
+ for ([_]u21{ ' ', 'b', Key.down }) |c| p.update(.{ .key = .{ .cp = c } });
+ const band = (try of(p, a, p.panes[id].?, id)).?;
+ var docs: usize = 0;
+ for (band.steps[0..band.nsteps]) |step| for (step.rows) |row| {
+ try std.testing.expect(std.mem.indexOfScalar(u8, row.text, '\n') == null);
+ if (step.doc) docs += 1;
+ };
+ try std.testing.expect(docs > 2);
+}
diff --git a/core/Core.zig b/core/Core.zig
index 11f254ab..5ce635f2 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -2028,6 +2028,15 @@ pub fn sync(p: *Pardes) void {
caret_row = std.mem.count(u8, shown.text[0..@min(shown.fromReal(cur), shown.text.len)], "\n");
}
if (!pane.tag_expanded) wanted = 1;
+ // Out of rest the head is the tag's text (TagState), and the tag
+ // keeps the rows its own text takes at least: a head shorter than
+ // it (a root's key cell, before its level shows) moved the body up
+ // and back down a moment later; a terminal's exactly those, its pty
+ // its body (a resize the program under it saw at every C-w and SPC).
+ if (pardes.TagState.hostOf(p) == id) {
+ const rest = layout.wantedTagRows(p, id);
+ wanted = if (pane.isTerminal()) rest else @max(wanted, rest);
+ }
pane.tag_rows = @intCast(@min(wanted, MAX_TAG_ROWS, @max(BOX_H, r.h -| 1)));
if (pane.collapsed) pane.tag_rows = BOX_H;
if (pane.focus == .tag and pane.prompt != .name) {
@@ -2035,7 +2044,7 @@ pub fn sync(p: *Pardes) void {
var top: usize = pane.tag_top;
if (cur < top) top = cur;
if (cur >= top + pane.tag_rows) top = cur + 1 - pane.tag_rows;
- pane.tag_top = @intCast(@min(top, lines - pane.tag_rows));
+ pane.tag_top = @intCast(@min(top, lines -| pane.tag_rows));
} else pane.tag_top = 0;
// The band unrolled under the tag's text pushes the body down:
// the tag's rows, as everything under them counts them.
diff --git a/core/TagState.zig b/core/TagState.zig
index a0ac6353..867b1391 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -486,21 +486,28 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
// 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.
+ // 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);
const tab = p.settings.tab;
const most: usize = if (pane.isTerminal()) @import("layout.zig").wantedTagRows(p, id) else 3;
- const room = most * tagline.tagWidth(p, id) -| panes.File.displayWidth(tab, prefix) -| panes.File.displayWidth(tab, hint) -| 2;
+ 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];
- for (bindings.level(p, cur.root, cur.path, &children)) |c| {
- const width = panes.File.displayWidth(tab, b.text.items) + 2 + bindings.keyName(c.key).len + 1 + panes.File.displayWidth(tab, c.label);
- if (width > room) {
- try b.put(" …");
+ var width = panes.File.displayWidth(tab, b.text.items);
+ 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);
break;
}
- try b.put(if (b.text.items.len > 0 and std.mem.endsWith(u8, b.text.items, "▸")) " " else " ");
+ try b.put(if (i == 0) " " else " ");
const lo: u32 = @intCast(b.text.items.len);
try b.styled(bindings.keyName(c.key), .key);
try b.put(" ");
@@ -808,3 +815,79 @@ test "a terminal's rolled level takes no more tag rows than its own text: its pt
try std.testing.expectEqual(tag_rows, pane.tag_rows);
try std.testing.expectEqual(rows, pane.rows);
}
+
+test "a rolled level fits its rows at every width: its `…`, its groups' `…` and a struck key are counted" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ 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 pane = p.panes[p.view().active].?;
+ for ([_]pardes.Key{ .{ .cp = ' ' }, .{ .cp = 'w', .ctrl = true } }) |root| for ([_]bool{ false, true }) |struck| {
+ p.update(.{ .key = root });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ // `x` is a child of neither level: struck, the level stays.
+ if (struck) p.update(.{ .key = .{ .cp = 'x' } });
+ for (30..161) |cols| {
+ p.update(.{ .resize = .{ .cols = @intCast(cols), .rows = 40 } });
+ try std.testing.expect(hostOf(p) != null);
+ try std.testing.expect((try tagline.shownTag(p, a, pane)).rows() <= 3);
+ }
+ toRest(p);
+ p.update(.{ .resize = .{ .cols = 120, .rows = 40 } });
+ };
+}
+
+test "a terminal's rolled level keeps its tag rows at every width, C-w's as SPC's: its pty is never resized" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml", .cols = 100, .rows = 30 });
+ defer p.deinit();
+ _ = pardes.exec.spawnTty(p, 0);
+ const shell = p.view().active;
+ const pane = p.panes[shell].?;
+ pane.body.mode = .normal;
+ for ([_]pardes.Key{ .{ .cp = ' ' }, .{ .cp = 'w', .ctrl = true } }) |root| for (30..131) |cols| {
+ p.update(.{ .resize = .{ .cols = @intCast(cols), .rows = 30 } });
+ p.sync();
+ const rows, const tag_rows = .{ pane.rows, pane.tag_rows };
+ p.update(.{ .key = root });
+ // Its key cell alone, before the level shows: shorter than the
+ // tag's own text, the rows it had.
+ p.sync();
+ try std.testing.expect(hostOf(p) == shell);
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ try std.testing.expectEqual(rows, pane.rows);
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ p.sync();
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ try std.testing.expectEqual(rows, pane.rows);
+ toRest(p);
+ };
+}
+
+test "a tag out of rest keeps its rows at rest at least: a root's key cell alone moves no body up" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 30 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ const pane = p.panes[p.view().active].?;
+ p.sync();
+ const rows, const tag_rows = .{ pane.rows, pane.tag_rows };
+ try std.testing.expect(tag_rows > 1);
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.sync();
+ try std.testing.expect(hostOf(p) != null);
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ try std.testing.expectEqual(rows, pane.rows);
+ // With the keyboard in the tag (whose top row follows its caret) too:
+ // C-w's key cell, a line, in a tag of more rows.
+ toRest(p);
+ pane.focus = .tag;
+ p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
+ p.sync();
+ try std.testing.expect(hostOf(p) != null);
+ try std.testing.expectEqual(tag_rows, pane.tag_rows);
+ try std.testing.expectEqual(@as(u16, 0), pane.tag_top);
+}