summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 19:52:55 -0300
committerGabriel Schneider <[email protected]>2026-10-29 19:53:05 -0300
commit32b80ad0393321d44f929e501e5515bbf6e51c12 (patch)
tree6dbf92426f6f07c1f1c030d542064b48ad6eaca8
parentb3b2768cc82105fa2a1845b7a7a3767c51173afb (diff)
downloadpardes-32b80ad0393321d44f929e501e5515bbf6e51c12.tar.gz
pardes-32b80ad0393321d44f929e501e5515bbf6e51c12.zip
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 <[email protected]>
-rw-r--r--docs/next-daemon.md41
-rw-r--r--docs/typ/reference.typ4
-rw-r--r--src/draw.zig3
-rw-r--r--src/panes.zig11
-rw-r--r--src/pardes.zig11
-rw-r--r--src/tagline.zig1
-rw-r--r--src/terminal.zig24
-rw-r--r--src/views.zig49
-rw-r--r--test/snapshots/views-pan.golden52
-rw-r--r--test/snapshots/views-pan.snap27
10 files changed, 194 insertions, 29 deletions
diff --git a/docs/next-daemon.md b/docs/next-daemon.md
index 3d4c8a08..e7ddcf5f 100644
--- a/docs/next-daemon.md
+++ b/docs/next-daemon.md
@@ -314,15 +314,23 @@ the ponytail lens:
workspace tag, prompts, messages, registers (decided), the macro being
recorded, look-hover (one pointer at a time), mouse sweeps, query
panes, search state, settings and theme, the effect and input queues,
- `needs_frame` (any change draws every view).
+ `needs_frame` (any change draws every view). A `.name` prompt (a
+ file's name drafted in its tag) is the view's that opened it
+ (`Pane.prompt_view`): only that view's focus leaving the pane drops it,
+ and its closing.
- **A terminal shown at two sizes** takes the size of the view that typed
into it last (`Pane.sized_by`, set by a key or a paste; a new pane's is
its maker's; a closed view's goes to the next to sync it). The others show
it at that size: `sync` resizes no pty for them, and `pane.cols/rows`
stay the terminal's own, so the terminal code's invariant (pane size is
- the emulator's) holds. ponytail: a smaller view sees its top rows, cut;
- panning to the cursor as tmux does is the upgrade, if a small view must
- follow a shell it never types into.
+ the emulator's) holds. A view shorter than the terminal is passed down
+ its top rows as far as keeps its cursor's row in sight, as tmux shows a
+ bigger window in a smaller client (`Pane.pan`, terminal.panFor: per view,
+ made in the step and again when a view is drawn out of turn, read where
+ the body's rows start, `Pane.scroll` and the body walk), an arrow in its
+ gutter's first row saying rows are above; a shell's prompt, at the
+ bottom, is never out of sight. ponytail: a panned view's mouse reports to
+ the terminal's program and its kitty images are placed as unpanned.
- **Panes come and go under parked views.** A view keeps the serial of
each slot when it goes out; unparked, the ids whose serial changed leave
its layout and its keyboard moves to its first pane left. A pane focused
@@ -390,8 +398,6 @@ the ponytail lens:
named in a path yet (a script's focus or layout is that view's).
- Every change draws every view (`needs_frame` is the session's); a
view's own dirtiness waits for a measurement that wants it.
- - Prompts are the pane's: a `.name` prompt drafted in one view is
- closed by another view's step, where that pane has not the keyboard.
- Dump, Restore and Handover keep one view, the live one.
- **What proved wrong in the design.** "Views" in the design were a
struct the core reads through; the swap made them cheaper and kept every
@@ -433,21 +439,24 @@ Two views (not gated): every frame draws both, so a change costs two
renders; a view switch copies ~60 fields and each pane's share, a few
microseconds.
-Gates, on the line rebased onto main's tty throughput fix (qzsouslm):
+Gates, on the line rebased onto main's screen-state terminals (mnlwlpvk):
-- `zig build replay -Dplatform=tty`: 112 snapshot scripts pass (the 110,
- views.snap and views-term.snap), their 130 tapes replay in all three
- replicas (390 runs, 29,355 digests); 20 monkey seeds at one view (60
- runs, 14,010 digests) and 20 at three views (60 runs, 9,720 digests);
- no divergence, no panic. views.snap: 75 digests a replica,
- views-term.snap 35.
-- Unit tests: tty 1478 of 1498 pass, 20 skipped; GUI 1549 of 1560, 9
+- `zig build replay -Dplatform=tty`: 113 snapshot scripts pass (the 110,
+ views.snap, views-term.snap and views-pan.snap), their 131 tapes replay
+ in all three replicas (393 runs, 29,436 digests); 20 monkey seeds at one
+ view (60 runs, 14,004 digests) and 20 at three views (60 runs, 9,666
+ digests); no divergence, no panic. views.snap: 75 digests a replica,
+ views-term.snap 35. core-test: 1117 of 1135, 18 skipped.
+- Unit tests (on qzsouslm): tty 1478 of 1498 pass, 20 skipped; GUI 1549 of 1560, 9
skipped and 2 failed, the same two that fail on phase 1's line (`tagline
pointer mapping retains physical grips...` and `a tag caret past its
- row's end glides...`). The views' own: 7 (own cursor, scroll, mode,
+ row's end glides...`). The views' own: 8 (own cursor, scroll, mode,
layout and focus; an edit and a register shared; a terminal sized by its
last typist; views closing; the other views drawn leave the digest; a
- view keeps its place in a text another edits).
+ view keeps its place in a text another edits; a short view keeps a tall
+ terminal's cursor in sight). views-pan.snap: a shell sized for the tall
+ view, its prompt and last lines in the short one under an arrow, then
+ typed into from the short one and sized for it.
- test/fs.py passes (with a TMPDIR short enough for the 9P sockets'
paths). test/daemon.py: 20 detach and attach cycles, then a second
terminal on the attached session, both drawn, detached from inside and
diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ
index 190adba7..ce2a45f1 100644
--- a/docs/typ/reference.typ
+++ b/docs/typ/reference.typ
@@ -1018,8 +1018,8 @@ to its end before the write is answered, and one that finds nothing fails,
each terminal or window its own layout, focus, cursors, selections,
modes, scroll and jumps, over the panes, texts, tags, terminals,
messages and registers they share. A terminal pane shown in two takes the
- size of the view that typed into it last; a smaller view shows its top
- rows. #word("Detach"), or a terminal closing, lets that view go and
+ size of the view that typed into it last; a shorter view shows the
+ rows down to its cursor, an arrow in the gutter when rows are above. #word("Detach"), or a terminal closing, lets that view go and
leaves the others. With none
attached, `size C R` sets the screen, messages clear by the clock, and a
pty reports its size in pixels at the last cell size (8×16 before any),
diff --git a/src/draw.zig b/src/draw.zig
index 4f9c6c87..0cc5c80d 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -958,6 +958,9 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
}
try body_layer.joinBody(p, s, arena, pane, r, id, active, rail.*);
+ // A terminal panned to its cursor in a view shorter than it: an arrow
+ // in the gutter's first body row says rows are above (views.zig).
+ if (pane.pan > 0) s.set(r.x, p.bodyTop(pane, r), "↑", .{ .fg = .{ .rgb = chrome.box } });
// A query's places' ticks, each in the track's cell of its row: chrome,
// painted with the rail (a pixel shell draws its own from the same list).
for (s.rail_ticks[0..s.nrail_ticks]) |tick| {
diff --git a/src/panes.zig b/src/panes.zig
index 71a04464..89f24eb6 100644
--- a/src/panes.zig
+++ b/src/panes.zig
@@ -30,7 +30,7 @@ pub const Pane = struct {
/// the pane's opens and readers; the other views' share of it (views.zig).
pub const replica = .{
.local = .{ "pv", "pv_known" },
- .derived = .{ "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "view", "notices" },
+ .derived = .{ "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "view", "notices", "pan" },
.authority = .{"fs"},
.len = .{ .{ "msg", "msg_len" }, .{ "msg_older", "msg_older_len" }, .{ "question", "question_len" }, .{ "shell_tail", "shell_tail_len" }, .{ "sel_snap", "nsel_snap" } },
};
@@ -309,6 +309,13 @@ pub const Pane = struct {
/// The view that last typed into it: a terminal shown at two sizes takes
/// that view's (Pardes.sync).
sized_by: u8 = 0,
+ /// A terminal shown in a view shorter than it (one that does not size
+ /// it): the rows its top is passed over by, so its cursor stays in
+ /// sight (terminal.panFor); 0 everywhere else.
+ pan: u16 = 0,
+ /// The view whose step a `.name` prompt is (tagline.draftName): only
+ /// that view's focus leaving the pane drops it.
+ prompt_view: u8 = 0,
pub const MessagePhase = enum { entering, shown, lingering, leaving };
/// One message line's animation: falling in, shown, lingering after the
@@ -543,7 +550,7 @@ pub const Pane = struct {
pub fn scroll(pane: *Pane) i32 {
if (pane.file) |f| return @intCast(f.scroll);
if (comptime Pdf.enabled) if (pane.pdf) |pv| return @intCast(pv.text_scroll);
- return pane.surfRow(terminal.gridOffset(pane));
+ return pane.surfRow(terminal.gridOffset(pane) + pane.pan);
}
pub fn wrapAt(pane: *Pane, vr: i32) struct { line: i32, at: i32, pad: i32 = 0 } {
diff --git a/src/pardes.zig b/src/pardes.zig
index 59233347..75e91ee9 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -7729,7 +7729,7 @@ pub const Pardes = struct {
// hands it back to its body, and a name drafted there is dropped.
if (id != p.active or p.header_focus) {
pane.focus = .body;
- if (pane.prompt == .name) pane.closePrompt();
+ if (pane.prompt == .name and pane.prompt_view == p.view) pane.closePrompt();
}
// A sweep over the tag is the tag's while it has the keyboard.
const swept = pane.sel[sel_slot];
@@ -7822,6 +7822,7 @@ pub const Pardes = struct {
pane.rows = rows;
if (pane.file) |*file| file.syntax_dirty = true;
}
+ pane.pan = panes.terminal.panFor(p, pane, r);
// A directory pane's entries follow its width, as acme's
// columns do (Dir.fit).
if (pane.file) |file| if (file.listing != null and r.h > pane.tag_rows) panes.Dir.fit(p, pane, pane.cols);
@@ -7856,10 +7857,10 @@ pub const Pardes = struct {
/// Whether the live view sizes terminal `pane`: a terminal shown at two
/// sizes takes the size of the view that typed into it last, and any
- /// view's once that one is gone. The others show it at that size.
- // ponytail: a view smaller than the terminal shows its top rows, the
- // rest cut; panning to its cursor, as tmux does, when a small view must
- // follow a busy shell it never types into.
+ /// view's once that one is gone. The others show it at that size, a
+ /// shorter one passed down to its cursor (`Pane.pan`, terminal.panFor).
+ // ponytail: a panned view's pointer reports to a terminal's program and
+ // its kitty images are placed as the unpanned rows are.
fn sizes(p: *Pardes, pane: *Pane) bool {
if (pane.sized_by == p.view) return true;
if (views.isOpen(p, pane.sized_by)) return false;
diff --git a/src/tagline.zig b/src/tagline.zig
index 79c2c09b..f669e98b 100644
--- a/src/tagline.zig
+++ b/src/tagline.zig
@@ -361,6 +361,7 @@ pub fn draftName(p: *Pardes, pane: *Pane, col: usize) void {
const name = p.gpa.dupe(u8, f.path) catch return;
pane.closePrompt();
pane.prompt = .name;
+ pane.prompt_view = p.view;
pane.input = .{ .what = .input, .own = name, .mode = .insert, .cur_pinned = true, .cur_col = @intCast(@min(name.len, panes.File.rawAtDisplay(name, col))) };
}
diff --git a/src/terminal.zig b/src/terminal.zig
index 0afbe43a..e737a831 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -395,8 +395,26 @@ pub fn visibleCursor(pane: *const Pane) ?GridCursor {
const cur = state.vt.screens.active.cursor;
const sb = scrollbar(pane);
const row = sb.total - sb.len + cur.y;
- if (row < sb.offset or row - sb.offset >= sb.len) return null;
- return .{ .x = @intCast(cur.x), .y = @intCast(row - sb.offset) };
+ if (row < sb.offset + pane.pan or row - sb.offset >= sb.len) return null;
+ return .{ .x = @intCast(cur.x), .y = @intCast(row - sb.offset - pane.pan) };
+}
+
+/// The rows terminal `pane`'s top is passed over by in a view whose rect
+/// `r` is shorter than it, one that does not size it (Pardes.sizes): as
+/// many as keep its cursor's row in sight, as tmux pans a bigger window in
+/// a smaller client. 0 in the view that sizes it, and in one tall enough.
+pub fn panFor(p: *const Pardes, pane: *const Pane, r: pardes.Rect) u16 {
+ if (comptime !enabled) return 0;
+ if (pane.sized_by == p.view or pane.collapsed or !pane.isTerminal()) return 0;
+ const shown = r.h -| pane.tag_rows;
+ if (shown == 0 or shown >= pane.rows) return 0;
+ const state = pane.terminal orelse return 0;
+ const sb = scrollbar(pane);
+ // The cursor's row in the viewport; past its end (scrolled back), its
+ // last row.
+ const row = sb.total - sb.len + state.vt.screens.active.cursor.y;
+ const at: usize = if (row < sb.offset) 0 else @min(row - sb.offset, pane.rows - 1);
+ return @intCast(@min(pane.rows - shown, (at + 1) -| shown));
}
/// Move the emulator's viewport by `delta` shell rows (negative scrolls back).
@@ -1886,7 +1904,7 @@ const BodyWalk = struct {
return .{
.pane = pane,
.goff = goff,
- .g = if (pane.body.mode == .tty) goff else pane.gridRow(off),
+ .g = if (pane.body.mode == .tty) goff + pane.pan else pane.gridRow(off),
.skip = if (pane.ovl) |o| @intCast(@max(0, off - pane.surfRow(o.row))) else 0,
};
}
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);
+}
diff --git a/test/snapshots/views-pan.golden b/test/snapshots/views-pan.golden
new file mode 100644
index 00000000..db63d29c
--- /dev/null
+++ b/test/snapshots/views-pan.golden
@@ -0,0 +1,52 @@
+== snap tall grid=80x24 cursor=4,16
+| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit
+| New Tty Find Grep Joincol Delcol
+|$ /tmp/pardes-snap/views-pan/cwd Tty+bash Save Mode Filter Collapse Del
+| 18
+| 19
+| 20
+| 21
+| 22
+| 23
+| 24
+| 25
+| 26
+| 27
+| 28
+| 29
+| 30
+| $
+| /tmp/pardes-snap/views-pan/cwd/+New Save Tty Collapse Del
+| 1
+== snap short-pans grid=60x12 cursor=4,8
+| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes
+| New Tty Find Grep Joincol Delcol
+|$ /tmp/pardes-snap/views-pan/cwd Tty+bash Save Mode Filter C
+| ollapse Del
+|↑ 27
+| 28
+| 29
+| 30
+| $
+| /tmp/pardes-snap/views-pan/cwd/+New Save Tty Collapse Del
+| 1
+== snap short-typed grid=60x12 cursor=4,8
+|4: 29
+|5: 30
+|6: $ echo typed-in-short
+|7: typed-in-short
+== snap tall-sees grid=80x24 cursor=4,7
+|3: 29
+|4: 30
+|5: $ echo typed-in-short
+|6: typed-in-short
+|7: $
+|8:
+|9:
+|10:
+|11:
+|12:
+|13:
+|14:
+|15:
+|16:
diff --git a/test/snapshots/views-pan.snap b/test/snapshots/views-pan.snap
new file mode 100644
index 00000000..3ba1ac5b
--- /dev/null
+++ b/test/snapshots/views-pan.snap
@@ -0,0 +1,27 @@
+# A terminal shown in a view shorter than it (src/views.zig): sized for the
+# tall view that typed into it, the short one passes over its top rows so
+# its cursor and prompt stay in sight, an arrow in the gutter saying rows
+# are above.
+config Verbose off
+start 24 80 views=2
+wait 8000 $
+stable 700 20000
+view 2
+resize 12 60
+stable 500 10000
+view 1
+text seq 1 30
+key enter
+wait 8000 30
+stable 500 10000
+snap tall
+view 2
+stable 500 10000
+snap short-pans
+text echo typed-in-short
+key enter
+stable 500 10000
+snap short-typed
+view 1
+stable 500 10000
+snap tall-sees