summaryrefslogtreecommitdiff
path: root/src/terminal.zig
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 /src/terminal.zig
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]>
Diffstat (limited to 'src/terminal.zig')
-rw-r--r--src/terminal.zig24
1 files changed, 21 insertions, 3 deletions
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,
};
}