beer/grid: scroll to fit image when cursor is near bottom

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ic95b18caca0c575b7d7452c87f9f1f956a6a6964
This commit is contained in:
raf 2026-06-27 00:45:43 +03:00
commit 3775e25cdf
No known key found for this signature in database
GPG key ID: 29D95B64378DB4BF

View file

@ -782,7 +782,25 @@ impl Grid {
rows: usize,
keep_cursor: bool,
) {
let (x0, y0) = (self.cursor.x, self.cursor.y);
let x0 = self.cursor.x;
// Scroll the screen to make vertical room for the image. Only scroll
// when the full screen is the active scroll region; a DECSTBM region
// or the alternate screen keeps the image clipped as before.
let y0 = if self.top == 0
&& self.bottom == self.rows - 1
&& self.alt_saved.is_none()
{
let y0_initial = self.cursor.y;
let scroll_n = (y0_initial + rows)
.saturating_sub(self.rows)
.min(y0_initial);
if scroll_n > 0 {
self.scroll_up(scroll_n);
}
y0_initial - scroll_n
} else {
self.cursor.y
};
for dy in 0..rows {
let cy = y0 + dy;
if cy >= self.rows {