Skip to content

Commit 96654a5

Browse files
clamp render area to terminal size (#1758)
this fixes a couple of panics that would happen when trying to render something larger than the terminal, or insert history lines when the top of the viewport is at y=0.
1 parent 861ba86 commit 96654a5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

codex-rs/tui/src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl App<'_> {
362362
AppState::GitWarning { .. } => 10,
363363
};
364364
let mut area = terminal.viewport_area;
365-
area.height = desired_height;
365+
area.height = desired_height.min(size.height);
366366
area.width = size.width;
367367
if area.bottom() > size.height {
368368
terminal

codex-rs/tui/src/insert_history.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ pub(crate) fn insert_history_lines(terminal: &mut tui::Tui, lines: Vec<Line>) {
3636
.backend_mut()
3737
.scroll_region_down(area.top()..screen_size.height, scroll_amount)
3838
.ok();
39-
let cursor_top = area.top() - 1;
39+
let cursor_top = area.top().saturating_sub(1);
4040
area.y += scroll_amount;
4141
terminal.set_viewport_area(area);
4242
cursor_top
4343
} else {
44-
area.top() - 1
44+
area.top().saturating_sub(1)
4545
};
4646

4747
// Limit the scroll region to the lines from the top of the screen to the

0 commit comments

Comments
 (0)