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
This commit is contained in:
Eric Traut authored and copyberry committed 2026-07-22 15:38:08 +00:00
1 parent c00e2e851c
commit 730ec92003
3 files changed
+36

No files matched your search

+20
View File
@@ -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::<Vec<_>>();
assert_eq!(widths, vec![usize::from(WIDTH); lines.len()]);
insta::assert_snapshot!(render_lines(&lines).join("\n"));
}
#[test]
#[cfg_attr(
target_os = "windows",