From 5f6e1af1a50ecab35cf9ce58041600622187af35 Mon Sep 17 00:00:00 2001 From: Jeremy Rose <172423086+nornagon-openai@users.noreply.github.com> Date: Thu, 21 Aug 2025 08:51:26 -0700 Subject: [PATCH] scroll instead of clear on boot (#2535) this actually works fine already in iterm without this change, but Terminal.app adds a bunch of excess whitespace when we clear all. https://github.com/user-attachments/assets/c5bd1809-c2ed-4daa-a148-944d2df52876 --- codex-rs/tui/src/tui.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/codex-rs/tui/src/tui.rs b/codex-rs/tui/src/tui.rs index 6af0d391b..4ec17ea8a 100644 --- a/codex-rs/tui/src/tui.rs +++ b/codex-rs/tui/src/tui.rs @@ -6,6 +6,7 @@ use std::time::Duration; use std::time::Instant; use crossterm::SynchronizedUpdate; +use crossterm::cursor; use crossterm::cursor::MoveTo; use crossterm::event::DisableBracketedPaste; use crossterm::event::EnableBracketedPaste; @@ -15,8 +16,7 @@ use crossterm::event::KeyEventKind; use crossterm::event::KeyboardEnhancementFlags; use crossterm::event::PopKeyboardEnhancementFlags; use crossterm::event::PushKeyboardEnhancementFlags; -use crossterm::terminal::Clear; -use crossterm::terminal::ClearType; +use crossterm::terminal::ScrollUp; use ratatui::backend::Backend; use ratatui::backend::CrosstermBackend; use ratatui::crossterm::execute; @@ -71,8 +71,14 @@ pub fn init() -> Result { set_panic_hook(); - // Clear screen and move cursor to top-left before drawing UI - execute!(stdout(), Clear(ClearType::All), MoveTo(0, 0))?; + // Instead of clearing the screen (which can drop scrollback in some terminals), + // scroll existing lines up until the cursor reaches the top, then start at (0, 0). + if let Ok((_x, y)) = cursor::position() + && y > 0 + { + execute!(stdout(), ScrollUp(y))?; + } + execute!(stdout(), MoveTo(0, 0))?; let backend = CrosstermBackend::new(stdout()); let tui = CustomTerminal::with_options(backend)?;