mirror of
https://github.com/openai/codex.git
synced 2026-08-23 13:09:46 +00:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 │
|
||||
╰──────────────────────────────────────────╯
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user