summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
6 files changed, 88 insertions, 11 deletions
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);
+}