From 32b80ad0393321d44f929e501e5515bbf6e51c12 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 19:52:55 -0300 Subject: views: a terminal shown in a view shorter than it is passed down to its cursor, a shell's prompt never out of sight, an arrow in the gutter where rows are above; a name drafted in a tag is the view's that opened it A terminal takes the size of the view that typed into it last; a shorter view used to show its top rows, the prompt below them cut. It now passes over as many as keep the cursor's row in sight, as tmux pans a bigger window in a smaller client: `Pane.pan` (per view, derived) is made in the step's sync and again when a view is drawn out of turn (views.unpark), by terminal.panFor (0 in the view that sizes it, in one tall enough, or folded), and read where the body's rows start: `Pane.scroll`, the body walk in tty mode, the visible cursor. One view never pans: the view that sizes a terminal returns 0 at its first test. A `.name` prompt (a file's name drafted in its tag) is the view's that opened it (`Pane.prompt_view`): another view's step, where that pane has not the keyboard, no longer drops it; its view closing does. views-pan.snap: a shell sized for a 24-row view, its last lines and prompt in a 12-row one under the arrow, then typed into from the short view and sized for it. A unit test: the short view's frame has the cursor's row, and the line on it, inside the pane. docs: the notes, the reference. Co-Authored-By: Claude Opus 5.5 --- src/views.zig | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src/views.zig') diff --git a/src/views.zig b/src/views.zig index e3ba5b4e..c847b987 100644 --- a/src/views.zig +++ b/src/views.zig @@ -53,7 +53,7 @@ pub const fields = [_][:0]const u8{ /// A pane's fields that are each view's own: where it is in the view's /// layout, which of its texts has the keyboard, how far it is scrolled, and /// what the view's step measured of it (its tag's rows, its bands). -const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "attached_to", "hscroll", "tag_scroll", "tag_top", "tag_rows", "view", "notices" }; +const pane_fields = [_][:0]const u8{ "focus", "vweight", "collapsed", "attached_to", "hscroll", "tag_scroll", "tag_top", "tag_rows", "view", "notices", "pan" }; /// The body's: its cursor, selections and mode. Its undo stays the pane's. const body_fields = [_][:0]const u8{ "mode", "cur_pinned", "cur_row", "cur_col", "msel", "vsel", "sels", "nsel", "select", "sticky_col", "restore_cursor", "last_edit", "reg_wait", "normal", "find_op", "find_ch" }; @@ -72,6 +72,7 @@ pub const PaneView = struct { tag_rows: u16 = 1, view: Pane.SessionView = .{}, notices: Pane.Notices = .{}, + pan: u16 = 0, body: Part(Text, &body_fields) = .{}, /// A document's scroll and size; a terminal's size is its pty's, which /// every view shows (sized by its last typist, `Pardes.sync`). @@ -216,6 +217,10 @@ fn unpark(p: *Pardes, k: u8) void { }; } layout.compute(p); + // Its terminals' cursors moved while it was out: each pan follows. + for (p.panes, 0..) |s, id| if (s) |pane| { + pane.pan = pardes.panes.terminal.panFor(p, pane, p.rects[id]); + }; } /// The pane with the keyboard is one the live view shows: focused where its @@ -285,6 +290,8 @@ pub fn close(p: *Pardes, k: u8) void { if (sels.len > 0) p.gpa.free(sels); pane.pv[k].body.sels = &.{}; pane.pv_known &= ~(@as(u8, 1) << @intCast(k)); + // A name it was drafting goes with it. + if (pane.prompt == .name and pane.prompt_view == k) pane.closePrompt(); }; p.views_open &= ~(@as(u8, 1) << @intCast(k)); } @@ -555,3 +562,43 @@ test "a view not live keeps its place in a text another view edits" { try testing.expectEqual(scrolled + 3, pane.file.?.scroll); try testing.expect(std.mem.startsWith(u8, pardes.panes.File.sourceLine(pane, 103), "line 101")); } + +test "a terminal shown in a view shorter than it keeps its cursor in sight" { + const gpa = testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 20 }); + defer p.deinit(); + const id = p.active; + const term = p.panes[id].?; + const k = p.openView().?; + p.toView(k); + p.update(.{ .resize = .{ .cols = 100, .rows = 50 } }); + p.update(.{ .key = .{ .cp = Key.right } }); + const rows = term.rows; + try testing.expect(rows > 30); + var out: std.ArrayList(u8) = .empty; + defer out.deinit(gpa); + for (1..rows) |i| try out.print(gpa, "row-{d}\r\n", .{i}); + try out.appendSlice(gpa, "LAST$ "); + p.update(.{ .output = .{ .pane = @intCast(id), .bytes = out.items } }); + // Sized for the tall view, it fits there whole: nothing is passed over. + try testing.expectEqual(@as(u16, 0), term.pan); + p.toView(0); + p.sync(); + try testing.expectEqual(rows, term.rows); + try testing.expect(term.pan > 0); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const s = try p.render(arena.allocator()); + const r = p.rects[id]; + // The cursor's row, the last, is on screen in the short view, inside + // the pane, and so is the line it is on. + const cursor = s.cursor.?; + try testing.expect(cursor.y >= r.y and cursor.y < r.y + r.h); + var row_text: std.ArrayList(u8) = .empty; + defer row_text.deinit(gpa); + for (0..s.cols) |x| try row_text.appendSlice(gpa, s.cells[@as(usize, cursor.y) * s.cols + x].grapheme()); + try testing.expect(std.mem.indexOf(u8, row_text.items, "LAST$") != null); + // Back in the tall view, its top is where it was. + p.toView(k); + try testing.expectEqual(@as(u16, 0), term.pan); +} -- cgit v1.3