summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Band.zig61
-rw-r--r--core/draw.zig21
-rw-r--r--test/snapshots/fsearch.golden2
3 files changed, 72 insertions, 12 deletions
diff --git a/core/Band.zig b/core/Band.zig
index e34b6a49..2b688a61 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -71,6 +71,8 @@ pub const max_steps = 4;
pub const max_spines = 12;
/// The narrowest a step is drawn (SPEC §3.6: box, spines, one 24-cell column).
pub const min_width = 24;
+/// The widest a list's rows are laid out (UX D5).
+const row_cells = 52;
/// A doc's rows, the fewest a band with one has.
const doc_rows = 4;
/// The body rows a band leaves its pane at least: it gives way first (UX D6).
@@ -375,26 +377,33 @@ pub fn docStep(p: *Pardes, arena: std.mem.Allocator, root: bindings.Root, path:
return .{ .rows = rows.items, .doc = true };
}
-/// Where each step goes: right of the spines, a rule's cell between steps;
-/// a doc takes what is left, wrapped to it. Narrow, the doc goes first,
-/// then the spines (the steps start at the band's left edge).
+/// Where each step goes (UX D5): from two cells right of the last spine,
+/// a rule's cell between steps; a level as wide as its widest row (two
+/// columns past nine), a list of rows `row_cells` at most, a doc the width
+/// the others leave, wrapped to it, `min_width` at least. Narrower than
+/// the steps (the hints already gone from the head), the band gives way:
+/// the doc leaves it, then the last step unrolled (a picker's acts) takes
+/// the place of the others; one step left is held to the room there is,
+/// its rows cut with `…` (Band.cutRow): the spines stay, nothing is clipped
+/// off the right edge.
fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !void {
const tab = p.settings.tab;
try band.findSpines(p, arena, pane, id);
- var x: u16 = if (band.nspines > 0) band.spines[band.nspines - 1] + 2 else 0;
+ const x0: u16 = if (band.nspines > 0) band.spines[band.nspines - 1] + 2 else 0;
var need: u16 = 0;
+ var lists: u8 = 0;
for (band.steps[0..band.nsteps]) |*step| {
if (step.doc) continue;
var widest: usize = 0;
for (step.rows) |row| widest = @max(widest, File.displayWidth(tab, row.text));
- const column: u16 = @intCast(@min(widest + 2, std.math.maxInt(u16) / 4, @max(min_width, band.columns -| x)));
+ const column: u16 = @intCast(@min(widest, row_cells) + 2);
step.width = if (step.two) 2 * column + 1 else column;
need += step.width + 2;
+ lists += 1;
}
- if (x + need > band.columns) {
- band.nspines = 0;
- x = 0;
- }
+ // The last list alone where they do not all fit.
+ var skip: u8 = if (x0 + need > band.columns and lists > 1) lists - 1 else 0;
+ var x = x0;
var kept: u8 = 0;
for (band.steps[0..band.nsteps]) |step| {
var placed = step;
@@ -403,6 +412,12 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi
if (room < min_width) continue;
placed.width = room;
placed.rows = try wrap(arena, tab, step.rows, room -| 1, band.height);
+ } else {
+ if (skip > 0) {
+ skip -= 1;
+ continue;
+ }
+ placed.width = @min(placed.width, @max(band.columns -| x, @min(min_width, band.columns)));
}
placed.x = x;
x +|= placed.width + 2;
@@ -562,6 +577,34 @@ fn layerRow(arena: std.mem.Allocator, layer: *const pardes.Layer, row: usize) ![
return out.items;
}
+test "a narrow band gives way and keeps its spines: the doc goes, the steps start two cells right of the last spine, no row past the band's edge; the spines run on through the tag's rows under the head" {
+ const Key = pardes.Key;
+ 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.sync();
+ try std.testing.expect(pane.tag_rows > 1);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ // Help for SPC l: its key cells `␣ l`, its rows, no room for a doc.
+ for ([_]u21{ ' ', 'l', '?' }) |c| p.update(.{ .key = .{ .cp = c } });
+ p.sync();
+ const band = (try of(p, a, pane, id)).?;
+ try std.testing.expectEqual(@as(u8, 2), band.nspines);
+ try std.testing.expectEqual(@as(u8, 1), band.nsteps);
+ try std.testing.expectEqual(band.spines[1] + 2, band.steps[0].x);
+ for (0..band.height) |y| try std.testing.expect(File.displayWidth(p.settings.tab, (try band.line(a, p.settings.tab, @intCast(y))).text) <= band.columns);
+ // The tag's second row, kept from rest under the head's one: a spine
+ // under each key cell.
+ const s = try p.render(a);
+ const r = p.view().rects[id];
+ const tag_y = p.tagTop(pane, r);
+ for (band.spines[0..band.nspines]) |col| try std.testing.expectEqualStrings("│", s.at(r.x + pardes.TAG_TEXT_INSET + col, tag_y + 1).grapheme());
+ p.update(.{ .key = .{ .cp = Key.escape } });
+}
+
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/draw.zig b/core/draw.zig
index f69f83c6..be4230c4 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -903,7 +903,8 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
}
for (ln.parts) |part| {
const end = @min(columns, part.col + part.width);
- if (part.row.on and part.col < end) t.tint(part.col, row, end - part.col, th.tag_sel_bg orelse th.sel_bg, th.sel_fg);
+ // The cursor's row across its step's width, its lead too (UX D5).
+ if (part.row.on and part.col < end) t.tint(part.col -| 2, row, end - (part.col -| 2), th.tag_sel_bg orelse th.sel_bg, th.sel_fg);
var c = part.col;
var b: usize = 0;
while (b < part.row.text.len and c < end) : (c += 1) {
@@ -999,7 +1000,11 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
var lines: [MAX_TAG_ROWS][]const u8 = @splat("");
var split = std.mem.splitScalar(u8, shown.text, '\n');
for (0..top) |_| _ = split.next();
- for (lines[0..rows]) |*line| line.* = split.next() orelse "";
+ var nlines: usize = 0;
+ for (lines[0..rows]) |*line| {
+ line.* = split.next() orelse continue;
+ nlines += 1;
+ }
// The keyboard's caret, as a row and a byte offset in that row's
// line: in the tag's own text when the tag has the keyboard, in the
// path while a name is drafted.
@@ -1026,6 +1031,18 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const start = @min(line.len, panes.File.rawAtDisplay(p.settings.tab, line, pane.tag_scroll));
_ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], tag_style);
}
+ // Out of rest the rows the tag keeps from rest under the head's own:
+ // the spines on through them, under the key cells (UX D5).
+ if (head) |h| if (top == 0 and nlines < rows and h.cells > 0) {
+ const first = lines[0];
+ for (h.spans[0..h.cells]) |cell| {
+ const at = prefix_len + cell.lo;
+ if (at > first.len) break;
+ const col = panes.File.rawDisplayCol(p.settings.tab, first, at);
+ if (col >= tw) break;
+ for (nlines..rows) |row| s.set(tx + @as(u16, @intCast(col)), tag_y + @as(u16, @intCast(row)), "│", .{ .fg = .{ .rgb = chrome.box }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline }); // P2: the rule role (UX D4)
+ }
+ };
// The pane's progress at its first row's right end, where the row has
// room for it (SPEC §10.2); out of rest the head's right block is
// there (UX D1).
diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden
index 905d2ef0..59037755 100644
--- a/test/snapshots/fsearch.golden
+++ b/test/snapshots/fsearch.golden
@@ -130,4 +130,4 @@
== snap cancel grid=180x31 cursor=97,23
== snap nomatch grid=180x31 cursor=118,16
|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › /MARK/ 2/3 › / zzqq = Look /zzqq/ 0 ⏎ land · M-⏎ as a list · C-r history · esc
-|17: ls
+|17: ls │