fix(tui): make streaming width deterministic before first render

This commit is contained in:
Felipe Coury
2026-04-06 13:36:23 -03:00
committed by Felipe Coury
parent 4c9b69b75d
commit 107af5e583
2 changed files with 12 additions and 13 deletions
+9 -13
View File
@@ -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<usize> {
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) {
@@ -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));