summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 10:52:34 -0300
committerGabriel Schneider <[email protected]>2026-11-25 10:52:34 -0300
commit1479c4ef253a0a05b1a64e368334ce07f9922244 (patch)
tree564500005b81235b181ec5ad89733f67d9985e78
parent854f2d4851044dc726f062ea2055c2f946f3a812 (diff)
downloadpardes-1479c4ef253a0a05b1a64e368334ce07f9922244.tar.gz
pardes-1479c4ef253a0a05b1a64e368334ce07f9922244.zip
Band, Messages: a doc step the band has no room for leaves it for the notice row: its first row and the first line of its text (`w Wrap: …`), in place of the path (UX D5's give-way 2, DESIGN.md E5.10; SPEC §3.6 "the doc step moves to the notice row"); TEST FIRST: Band.zig "a doc the band has no room for leaves it for the notice row: its first row and the first line of its text, in place of the path" (Help for SPC l at 44 columns: on the base the doc was dropped from the band and said nowhere; the test did not compile there: Band had no `left`); THE CHANGE: Band.place keeps the doc step it drops (`Band.left`); Band.docLeft works the live view's band out from the state (the host's, as the frame's is, in a room on the stack: `Pane.prefix_room`) and says `first row: first line of the text`; Messages.noticeRow says it where the path would be, after a picker's sentence and before any message (the band is the state the keyboard is in, as the sentence is), cut from the right with `…` like a message (E5.4); noticeRow takes the session mutable for it (Band.of's own signature; its callers, draw and the mouse, have one); at rest (no host) docLeft answers at once, so a frame at rest costs nothing more; READING (where D5 is not exact): "its first line" read as the doc step's first row (`k Label`) and the first line of its text, as TagState.lastUsed says a rolled level's leaf; a group's doc says its first child; no golden moved (none has a band too narrow for its doc); core-test 1090/1261 (171 skipped), process-test 0 of 147 failed (3 skipped)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
-rw-r--r--core/Band.zig51
-rw-r--r--core/Messages.zig16
2 files changed, 61 insertions, 6 deletions
diff --git a/core/Band.zig b/core/Band.zig
index f2a86d07..cdeaf19b 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -100,6 +100,9 @@ nsteps: u8 = 0,
height: u16 = 0,
/// The band's width at the tagline's pitch.
columns: u16 = 0,
+/// The doc step it had no room for (UX D5's give-way): the notice row
+/// says its first line (`docLeft`).
+left: ?Step = null,
/// The rows the band under pane `id`'s tag takes in the live view, from
/// its state alone: the layout's term, asked before any frame is made.
@@ -448,7 +451,10 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi
var placed = step;
if (step.doc) {
const room = band.columns -| x;
- if (room < min_width) continue;
+ if (room < min_width) {
+ band.left = step;
+ continue;
+ }
placed.width = room;
placed.rows = try wrap(arena, tab, step.rows, room -| 1, band.height);
} else {
@@ -577,6 +583,26 @@ pub fn line(band: *const Band, arena: std.mem.Allocator, tab: u16, y: u16) !Line
return .{ .text = text.items, .parts = parts.items };
}
+/// The first line of the doc the live view's band had no room for (UX
+/// D5's give-way): its first row and the first line of its text after it
+/// (`w Wrap: Toggles soft wrap`), into `buf`; what the notice row says in
+/// place of the path while the band shows. Worked out from the state as
+/// the frame's band is, in a room of its own on the stack.
+pub fn docLeft(p: *Pardes, buf: []u8) ?[]const u8 {
+ const id = TagState.hostOf(p) orelse return null;
+ const pane = p.panes[id] orelse return null;
+ if (takes(p, id) == 0) return null;
+ var room: [Pane.prefix_room]u8 = undefined;
+ var fba = std.heap.FixedBufferAllocator.init(&room);
+ const band = (of(p, fba.allocator(), pane, id) catch return null) orelse return null;
+ const doc = band.left orelse return null;
+ if (doc.rows.len == 0) return null;
+ const first = doc.rows[0].text;
+ if (doc.rows.len == 1) return std.fmt.bufPrint(buf, "{s}", .{first}) catch null;
+ const text = doc.rows[1].text;
+ return std.fmt.bufPrint(buf, "{s}: {s}", .{ first, text[0 .. std.mem.indexOfScalar(u8, text, '\n') orelse text.len] }) catch null;
+}
+
/// Whether row `row`'s meta fits `room` cells after its text.
pub fn metaShown(tab: u16, row: Row, room: u16) bool {
return row.meta.len > 0 and File.displayWidth(tab, row.text) + 2 + File.displayWidth(tab, row.meta) <= room;
@@ -756,6 +782,29 @@ test "Help's rows say the chord, two blanks and the word; the group is the row's
} else return error.TestUnexpectedResult;
}
+test "a doc the band has no room for leaves it for the notice row: its first row and the first line of its text, in place of the path" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 44, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ const id = p.view().active;
+ p.messages.live_len = 0;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ var buf: [pardes.Messages.notice_row_cap]u8 = undefined;
+ // Help for SPC l at 44 columns: no room for its doc.
+ for ([_]u21{ ' ', 'l', '?' }) |c| p.update(.{ .key = .{ .cp = c } });
+ const band = (try of(p, a, pane, id)).?;
+ const doc = band.left.?;
+ const row = pardes.Messages.noticeRow(p, 60, &buf);
+ const left = row.text[0..row.left];
+ try std.testing.expect(std.mem.startsWith(u8, left, doc.rows[0].text) and std.mem.indexOf(u8, left, ": ") != null);
+ try std.testing.expect(std.mem.indexOf(u8, left, "test.txt") == null);
+ // At rest, the path again.
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expect(std.mem.startsWith(u8, pardes.Messages.noticeRow(p, 60, &buf).text, "/test.txt"));
+}
+
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();
diff --git a/core/Messages.zig b/core/Messages.zig
index 725f5a99..b89b9676 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -689,7 +689,7 @@ pub const Row = struct {
/// pitch (Layer.capacity) is cut to it.
pub const notice_row_cap = 1024;
-pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row {
+pub fn noticeRow(p: *Pardes, width: usize, out: *[notice_row_cap]u8) Row {
const m = &p.messages;
const tab = p.settings.tab;
// A rolled level's last leaf, while the level shows: what it does, the
@@ -708,10 +708,16 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row {
live += 1;
if (s.kind == .question) questions += 1;
}
- // While a picker previews, its sentence (UX D7), before any message.
+ // While a picker previews, its sentence (UX D7), before any message;
+ // while a band shows with no room for its doc, the doc's first line
+ // (UX D5's give-way).
const said = pardes.Pick.sentence(p, &w);
- const lead = if (said == null) m.headline() else null;
- if (said != null) {} else if (lead) |s| {
+ var doc_buf: [notice_row_cap]u8 = undefined;
+ const doc = if (said == null) pardes.Band.docLeft(p, &doc_buf) else null;
+ const lead = if (said == null and doc == null) m.headline() else null;
+ if (said != null) {} else if (doc) |line| {
+ w.writeAll(line) catch {};
+ } else if (lead) |s| {
w.print("{s} ", .{s.kind.glyph()}) catch {};
// Its cause first, unless its words name it already.
const words = s.words();
@@ -744,7 +750,7 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row {
const room = width -| (if (tail_w > 0) tail_w + 2 else 0);
var cut = left_end;
if (panes.File.displayWidth(tab, out[0..cut]) > room) {
- if (said == null and lead == null) {
+ if (said == null and doc == null and lead == null) {
var from: usize = 0;
while (from < left_end and panes.File.displayWidth(tab, out[from..left_end]) > room -| 1) {
from += 1;