diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Band.zig | 35 | ||||
| -rw-r--r-- | core/Core.zig | 31 | ||||
| -rw-r--r-- | core/TagState.zig | 9 | ||||
| -rw-r--r-- | core/draw.zig | 18 | ||||
| -rw-r--r-- | core/layout.zig | 26 | ||||
| -rw-r--r-- | core/views.zig | 23 |
6 files changed, 98 insertions, 44 deletions
diff --git a/core/Band.zig b/core/Band.zig index 507f1bee..c1ae2c37 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -626,14 +626,15 @@ 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" { +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 band starts on the row under the head, in the rows the tag keeps from rest" { 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); + const rest = pane.tag_rows; + try std.testing.expect(rest > 1); var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); @@ -645,15 +646,41 @@ test "a narrow band gives way and keeps its spines: the doc goes, the steps star 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. + // The band on the row under the head's one, in the row the tag keeps + // from rest (UX E3): never a blank row between the head and its rows, + // the body under whichever is lower. const s = try p.render(a); const r = p.view().rects[id]; const tag_y = p.tagTop(pane, r); + try std.testing.expectEqual(@as(u16, 1), pane.tag_rows - pane.band_rows); + try std.testing.expectEqual(@max(rest, 1 + band.height), pane.tag_rows); + try std.testing.expectEqual(tag_y + 1, bandLayer(p, id).?.viewport.y); for (band.spines[0..band.nspines]) |col| try std.testing.expectEqualStrings("│", s.at(r.x + pardes.TAG_TEXT_INSET + col, tag_y + 1).grapheme()); + try std.testing.expect(std.mem.indexOf(u8, try layerRow(a, bandLayer(p, id).?, 0), "▶") != null); p.update(.{ .key = .{ .cp = Key.escape } }); } +test "out of rest with no band, the rows a tag keeps from rest stay blank: a spine hangs only where a band row is" { + 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(); + const rest = pane.tag_rows; + try std.testing.expect(rest > 1); + // A search prompt: a key cell in its head, no band under it. + p.update(.{ .key = .{ .cp = '/', .text = "/" } }); + p.sync(); + try std.testing.expectEqual(@as(u16, 0), pane.band_rows); + try std.testing.expectEqual(rest, pane.tag_rows); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const s = try p.render(frame.allocator()); + const r = p.view().rects[id]; + const tag_y = p.tagTop(pane, r); + for (1..rest) |row| for (0..r.w) |x| try std.testing.expect(!std.mem.eql(u8, "│", s.at(r.x + @as(u16, @intCast(x)), tag_y + @as(u16, @intCast(row))).grapheme())); +} + 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/Core.zig b/core/Core.zig index 5b6eba75..cd2254c2 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -2043,13 +2043,15 @@ pub fn sync(p: *Pardes) void { } 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); + // keeps the rows its own text takes at rest 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). A band takes the kept rows first (below). + var kept: usize = 0; + if (pardes.TagState.hostOf(p) == id and !pane.collapsed) { + kept = layout.wantedTagRows(p, id); + if (pane.isTerminal()) wanted = kept; } pane.tag_rows = @intCast(@min(wanted, MAX_TAG_ROWS, @max(BOX_H, r.h -| 1))); if (pane.collapsed) pane.tag_rows = BOX_H; @@ -2060,11 +2062,16 @@ pub fn sync(p: *Pardes) void { if (cur >= top + pane.tag_rows) top = cur + 1 - 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. - // A terminal's or a kind's is drawn over its body instead (Band.over). - pane.band_rows = if (pane.collapsed or pardes.Band.over(pane)) 0 else @min(pardes.Band.takes(p, id), r.h -| pane.tag_rows -| pardes.Band.body_rows); - pane.tag_rows += pane.band_rows; + // The band unrolled under the head pushes the body down: the tag's + // rows, as everything under them counts them. Its first row is the + // one under the head's last, and the rows the tag keeps from rest + // are its own (UX E3: never a blank row between a head and its + // rows); with no band they stay the tag's, blank. A terminal's or + // a kind's is drawn over its body instead (Band.over). + const band = if (pane.collapsed or pardes.Band.over(pane)) 0 else @min(pardes.Band.takes(p, id), r.h -| pane.tag_rows -| pardes.Band.body_rows); + const keep: u16 = @intCast(@min(kept, MAX_TAG_ROWS, @max(BOX_H, r.h -| 1))); + pane.band_rows = if (band == 0) 0 else @max(band, keep -| pane.tag_rows); + pane.tag_rows = @max(keep, pane.tag_rows + pane.band_rows); const cols = @max(1, r.w -| config.GUTTER); // The tag steals the top rows. The pty is what the pane shows // (layout keeps a terminal two body rows where the window has diff --git a/core/TagState.zig b/core/TagState.zig index 5ae2d0b6..761eec48 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -1270,13 +1270,16 @@ test "a tag out of rest keeps its rows at rest at least: a level shorter than it p.sync(); const rows, const tag_rows = .{ pane.rows, pane.tag_rows }; try std.testing.expect(tag_rows > 1); - // Help's head, a row, its band under the rows the tag keeps. + // Help's head, a row, its band from the row under it: the rows the tag + // keeps from rest are the band's first (UX E3), and the body gives only + // what the band takes past them. p.update(.{ .key = .{ .cp = ' ' } }); p.update(.{ .key = .{ .cp = '?' } }); p.sync(); try std.testing.expect(hostOf(p) != null); - try std.testing.expectEqual(tag_rows, pane.tag_rows - pane.band_rows); - try std.testing.expectEqual(rows, pane.rows + pane.band_rows); + try std.testing.expectEqual(@as(u16, 1), pane.tag_rows - pane.band_rows); + try std.testing.expect(pane.tag_rows >= tag_rows); + try std.testing.expectEqual(rows + tag_rows, pane.rows + pane.tag_rows); // With the keyboard in the tag (whose top row follows its caret) too: // C-w's level, a line, in a tag of more rows. toRest(p); diff --git a/core/draw.zig b/core/draw.zig index a459e3e9..685f67ea 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -1053,11 +1053,7 @@ 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(); - var nlines: usize = 0; - for (lines[0..rows]) |*line| { - line.* = split.next() orelse continue; - nlines += 1; - } + for (lines[0..rows]) |*line| line.* = split.next() orelse continue; // 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. @@ -1084,18 +1080,6 @@ 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..], text_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 = inks.rule }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline }); - } - }; // 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/core/layout.zig b/core/layout.zig index 5550ef4a..2a5d2cf3 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -600,6 +600,22 @@ pub fn wantedTagRows(p: *Pardes, id: usize) u16 { return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS))); } +/// The rows pane `id`'s tag's text takes now: out of rest its head +/// (TagState) after what of its prefix stays (UX D1), wrapped at its width +/// as Pardes.sync wraps it; at rest what wantedTagRows says. +fn headRows(p: *Pardes, id: usize) u16 { + const pane = p.panes[id] orelse return BOX_H; + if (pane.collapsed or !pane.tag_expanded) return BOX_H; + var wrap_room: [Pane.prefix_room]u8 = undefined; + var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room); + const wa = wrap_fba.allocator(); + const prefix = tagline.prefixIn(p, wa, pane) catch return pane.tag_rows; + const tail = tagline.shownTail(p, wa, pane) catch return pane.tag_rows; + const whole = std.mem.concat(wa, u8, &.{ prefix, tail }) catch return pane.tag_rows; + const shown = tagline.wrapTag(p.settings.tab, wa, whole, tagline.tagWidth(p, id)) catch return pane.tag_rows; + return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS))); +} + /// The rows a placement, and a `size`, leave a pane: its tag at its width /// and `min_body_rows`. The one minimum both ask. pub fn minRows(p: *Pardes, id: usize) u16 { @@ -1436,6 +1452,9 @@ pub fn compute(p: *Pardes) void { var vsum: f32 = 0; for (0..p.view().cols[c].n) |k| { if (p.panes[v.cols[c].panes[k]]) |pane| vsum += pane.vweight; + // Its width before its height: a band's floor wraps its tag at + // it (floorRows). + v.rects[v.cols[c].panes[k]] = .{ .x = x, .w = cw }; } if (vsum <= 0) vsum = 1; @@ -1478,7 +1497,12 @@ fn floorRows(p: *Pardes, id: usize) u16 { const pane = p.panes[id] orelse return 0; const band = if (pardes.Band.over(pane)) 0 else pardes.Band.takes(p, id); if (band > 0) { - const above = @max(1, pane.tag_rows -| pane.band_rows) + band; + // Over its body as Pardes.sync lays it out (UX E3): the head's rows + // and the band under them, or the rows the tag keeps from rest + // where those are more; worked out from the state, never the last + // sync's rows (the first layout after a head changed read the + // rows of the one before, and the next moved the body). + const above = @max(wantedTagRows(p, id), headRows(p, id) + band); // A body of 60 % is one and a half times what is above it. return above + @max(pardes.Band.body_rows, (3 * above + 1) / 2); } diff --git a/core/views.zig b/core/views.zig index 02628e63..a81e8430 100644 --- a/core/views.zig +++ b/core/views.zig @@ -611,26 +611,35 @@ test "a view not live with its band open, dumped and loaded, draws before its ne _ = try drawOne(q, 0, .{ .ctx = null, .f = null }); } -test "a band its sync held short under a tag of two rows, dumped and loaded: its rows are the never-loaded session's, and so is the next layout" { +test "a band its sync held short under a head of two rows, dumped and loaded: its rows are the never-loaded session's, and so is the next layout" { const gpa = std.testing.allocator; const dump = @import("dump.zig"); - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 18 }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }); defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "alpha.zig", .data = "const alpha = 1;\n" }); + var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; const pane = try p.setTestFile("one\n"); + gpa.free(pane.file.?.path); + pane.file.?.path = try std.Io.Dir.path.join(gpa, &.{ dir, "one.txt" }); const host = p.view().active; p.newScratchBelow(host); const low = p.view().active; p.view().active = host; p.sync(); - p.update(.{ .key = .{ .cp = ' ' } }); - p.update(.{ .key = .{ .cp = Key.down } }); - // The column has not the rows: the band is held under what it wants, - // under a tag of two rows of its own. + // Find in the pane itself (it reads): its head and its act row over + // the band, which the short column holds under what it wants. + p.stream.engine = .walk; + pardes.Pick.open(p, host, .find, "", "", ""); + p.sync(); try testing.expect(pane.band_rows > 0 and pane.band_rows < pardes.Band.takes(p, host)); try testing.expect(pane.tag_rows - pane.band_rows >= 2); const bytes = try dump.byteDump(p); defer gpa.free(bytes); - const q = try dump.load(gpa, .{ .tty_only = true, .cols = 40, .rows = 18 }, bytes, null); + const q = try dump.load(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }, bytes, null); defer q.deinit(); try testing.expectEqual(pane.band_rows, q.panes[host].?.band_rows); // The next step lays the column out from the band's floor (layout |
