summaryrefslogtreecommitdiff
path: root/src/panes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/panes.zig')
-rw-r--r--src/panes.zig14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/panes.zig b/src/panes.zig
index edd7038f..9a6802d0 100644
--- a/src/panes.zig
+++ b/src/panes.zig
@@ -6273,6 +6273,13 @@ pub const Terminal = struct {
state.vt.screens.active.scroll(.{ .delta_row = delta });
}
+ /// Is the viewport already showing the last row of output?
+ pub fn atBottom(pane: *const Pane) bool {
+ if (comptime !enabled) return true;
+ const sb = scrollbar(pane);
+ return sb.offset + sb.len >= sb.total;
+ }
+
/// Snap the viewport back onto live output.
pub fn followOutput(pane: *Pane) void {
if (comptime !enabled) return;
@@ -6559,10 +6566,14 @@ pub const Terminal = struct {
const has_positions = pane.ovl != null or pane.cur_pinned or pane.vsel.active or
pane.msel.active or pane.nsel > 0 or pane.append_at != null or pane.look_at != null or
pane.ed_undo_len > 0 or pane.ed_redo_len > 0 or pointerRowCount(pane) > 0;
+ // Sticky bottom, as every other terminal does it: output drags the
+ // viewport down only when the viewport was already on the last row, so
+ // a reader scrolled back into the scrollback stays where they scrolled.
+ const at_bottom = atBottom(pane);
if (has_positions) ingestWithPositions(pane, bytes) else ingest(pane, bytes);
p.shell_rows.markStale(pane);
const body_mode = if (pane.tag_edit) pane.tag_mode else pane.mode;
- if (body_mode == .tty) followOutput(pane);
+ if (body_mode == .tty and at_bottom) followOutput(pane);
}
const RowPin = struct { pin: ?*ghostty_vt.Pin = null, offset: i32 = 0 };
@@ -6890,6 +6901,7 @@ pub const Terminal = struct {
};
pane.mode = .tty;
+ followOutput(pane); // entering raw mode is a request for the live shell
pane.msel.active = false;
pane.vsel.active = false;
pane.nsel = 0;