From 730ec920032ba6bd16c97106616fb53cda8ae96b Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Wed, 22 Jul 2026 15:24:33 +0000 Subject: [PATCH] Clamp session headers to narrow terminal widths (#34775) ## Why Session header rows can exceed the available inner width when the terminal is narrow, causing the bordered header to render wider than its requested width. ## What changed Truncate each session header row to the available inner width and append an ellipsis when content overflows. ## Testing Add a snapshot test for a 44-column session header and assert that every rendered line matches the requested width. GitOrigin-RevId: 7cf0ea48aa95a6f1ddd1a9dbb7c7fb70bdbcb5a3 --- codex-rs/tui/src/history_cell/session.rs | 5 +++++ ...session_header_clamps_to_narrow_width.snap | 11 ++++++++++ codex-rs/tui/src/history_cell/tests.rs | 20 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 codex-rs/tui/src/history_cell/snapshots/codex_tui__history_cell__tests__session_header_clamps_to_narrow_width.snap diff --git a/codex-rs/tui/src/history_cell/session.rs b/codex-rs/tui/src/history_cell/session.rs index 695efc30f9..b4a2ca050d 100644 --- a/codex-rs/tui/src/history_cell/session.rs +++ b/codex-rs/tui/src/history_cell/session.rs @@ -1,6 +1,7 @@ //! Session headers, onboarding guidance, and transcript cards. use super::*; +use crate::line_truncation::truncate_line_with_ellipsis_if_overflow; pub(crate) const SESSION_HEADER_MAX_INNER_WIDTH: usize = 56; // Just an eyeballed value @@ -390,6 +391,10 @@ impl HistoryCell for SessionHeaderHistoryCell { ])); } + let lines = lines + .into_iter() + .map(|line| truncate_line_with_ellipsis_if_overflow(line, inner_width)) + .collect(); with_border(lines) } diff --git a/codex-rs/tui/src/history_cell/snapshots/codex_tui__history_cell__tests__session_header_clamps_to_narrow_width.snap b/codex-rs/tui/src/history_cell/snapshots/codex_tui__history_cell__tests__session_header_clamps_to_narrow_width.snap new file mode 100644 index 0000000000..2baf486e51 --- /dev/null +++ b/codex-rs/tui/src/history_cell/snapshots/codex_tui__history_cell__tests__session_header_clamps_to_narrow_width.snap @@ -0,0 +1,11 @@ +--- +source: tui/src/history_cell/tests.rs +expression: "render_lines(&lines).join(\"\\n\")" +--- +╭──────────────────────────────────────────╮ +│ >_ OpenAI Codex (vtest) │ +│ │ +│ model: gpt-5.6-sol xhigh fast … │ +│ directory: project │ +│ permissions: YOLO mode │ +╰──────────────────────────────────────────╯ diff --git a/codex-rs/tui/src/history_cell/tests.rs b/codex-rs/tui/src/history_cell/tests.rs index 6dbf016769..565055e35d 100644 --- a/codex-rs/tui/src/history_cell/tests.rs +++ b/codex-rs/tui/src/history_cell/tests.rs @@ -6,6 +6,7 @@ use crate::exec_cell::ExecCall; use crate::exec_cell::ExecCell; use crate::legacy_core::config::Config; use crate::legacy_core::config::ConfigBuilder; +use crate::line_truncation::line_width; use crate::session_state::ThreadSessionState; use crate::wrapping::word_wrap_lines; use codex_app_server_protocol::AskForApproval; @@ -1568,6 +1569,25 @@ fn session_header_hides_fast_status_when_disabled() { assert!(!model_line.contains("fast")); } +#[test] +fn session_header_clamps_to_narrow_width() { + const WIDTH: u16 = 44; + let cell = SessionHeaderHistoryCell::new( + "gpt-5.6-sol".to_string(), + Some(ReasoningEffortConfig::XHigh), + /*show_fast_status*/ true, + PathBuf::from("project"), + "test", + ) + .with_yolo_mode(/*yolo_mode*/ true); + + let lines = cell.display_lines(WIDTH); + let widths = lines.iter().map(line_width).collect::>(); + + assert_eq!(widths, vec![usize::from(WIDTH); lines.len()]); + insta::assert_snapshot!(render_lines(&lines).join("\n")); +} + #[test] #[cfg_attr( target_os = "windows",