From 107af5e583abd1a4ad40cf49a7fd219c117e70fb Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Tue, 17 Feb 2026 22:04:04 -0300 Subject: [PATCH] fix(tui): make streaming width deterministic before first render --- codex-rs/tui/src/chatwidget.rs | 22 ++++++++----------- .../src/chatwidget/tests/status_and_layout.rs | 3 +++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index 84bff7ce91..52c6b1729f 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -229,7 +229,6 @@ use crossterm::event::KeyCode; use crossterm::event::KeyEvent; use crossterm::event::KeyEventKind; use crossterm::event::KeyModifiers; -use crossterm::terminal; use rand::Rng; use ratatui::buffer::Buffer; use ratatui::layout::Rect; @@ -4237,18 +4236,15 @@ impl ChatWidget { } fn current_stream_width(&self, reserved_cols: usize) -> Option { - self.last_rendered_width - .get() - .or_else(|| terminal::size().ok().map(|(w, _)| usize::from(w))) - .and_then(|w| { - if w == 0 { - None - } else { - // Keep a 1-column minimum for active stream controllers so they can - // continue accepting deltas on ultra-narrow layouts. - Some(crate::width::usable_content_width(w, reserved_cols).unwrap_or(1)) - } - }) + self.last_rendered_width.get().and_then(|w| { + if w == 0 { + None + } else { + // Keep a 1-column minimum for active stream controllers so they can + // continue accepting deltas on ultra-narrow layouts. + Some(crate::width::usable_content_width(w, reserved_cols).unwrap_or(1)) + } + }) } pub(crate) fn on_terminal_resize(&mut self, width: u16) { diff --git a/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs b/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs index 3e2a52a9d4..df8a2281e1 100644 --- a/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs +++ b/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs @@ -116,6 +116,9 @@ async fn turn_started_uses_runtime_context_window_before_first_token_count() { async fn current_stream_width_clamps_to_minimum_when_reserved_columns_exhaust_width() { let (chat, _rx, _op_rx) = make_chatwidget_manual(None).await; + chat.last_rendered_width.set(None); + assert_eq!(chat.current_stream_width(2), None); + chat.last_rendered_width.set(Some(2)); assert_eq!(chat.current_stream_width(2), Some(1));