diff options
Diffstat (limited to 'core/Band.zig')
| -rw-r--r-- | core/Band.zig | 51 |
1 files changed, 50 insertions, 1 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(); |
