mirror of
https://github.com/openai/codex.git
synced 2026-11-29 00:00:54 +00:00
## What changed - Replace `FooterContent` and the separate layout cache with a `StatusLine` that owns native or extension content and caches its layout by bounds. - Move footer padding into the caller's layout and retain cached wrapping for unchanged agent-labeled status lines. - Remove extension-to-single-line conversion and render prepared UI trees directly within their allotted rectangles. ## Testing Extend composer coverage to verify that replacing measured extension content updates the displayed rows. Adapt status-line and UI-tree tests to exercise direct rendering, clipping, hyperlinks, and viewport bounds. GitOrigin-RevId: 72273c87d689b8b59748ab243793a9e2a45f4884
95 lines
3.1 KiB
Rust
95 lines
3.1 KiB
Rust
#![cfg(test)]
|
|
|
|
use super::StatusLine;
|
|
use super::StatusLineFocus;
|
|
use crate::terminal_hyperlinks::HyperlinkLine;
|
|
use crate::terminal_hyperlinks::osc8_hyperlink;
|
|
use pretty_assertions::assert_eq;
|
|
use ratatui::buffer::Buffer;
|
|
use ratatui::layout::Rect;
|
|
|
|
#[test]
|
|
fn clipped_links_keep_their_cells_after_a_halfwidth_katakana_grapheme() {
|
|
let project_url = "https://example.com/project";
|
|
let pr_url = "https://example.com/pr/42";
|
|
let mut line = HyperlinkLine::default();
|
|
line.push_span("ガ".into(), Some(project_url));
|
|
line.push_span(" · ".into(), /*destination*/ None);
|
|
line.push_span("PR #42".into(), Some(pr_url));
|
|
|
|
let area = Rect::new(
|
|
/*x*/ 0, /*y*/ 0, /*width*/ 10, /*height*/ 1,
|
|
);
|
|
let mut buf = Buffer::empty(area);
|
|
StatusLine::from(line).render(area, &mut buf, StatusLineFocus::Focused);
|
|
assert_eq!(buf[(0, 0)].symbol(), osc8_hyperlink(project_url, "ガ"));
|
|
for (x, ch) in (2..5).zip(" · ".chars()) {
|
|
assert_eq!(buf[(x, 0)].symbol(), ch.to_string());
|
|
}
|
|
for (x, ch) in (5..9).zip("PR #".chars()) {
|
|
assert_eq!(
|
|
buf[(x, 0)].symbol(),
|
|
osc8_hyperlink(pr_url, &ch.to_string())
|
|
);
|
|
}
|
|
assert_eq!(buf[(9, 0)].symbol(), "…");
|
|
}
|
|
|
|
#[test]
|
|
fn arabic_prefix_keeps_link_on_the_painted_cells_at_exact_fit_and_overflow() {
|
|
let url = "https://example.com/pr/42";
|
|
let mut line = HyperlinkLine::from("لا · ");
|
|
line.push_span("PR #42".into(), Some(url));
|
|
assert_eq!(line.width(), 11);
|
|
let content = StatusLine::from(line);
|
|
|
|
for (width, visible_link) in [(11, "PR #42"), (10, "PR #")] {
|
|
let area = Rect::new(/*x*/ 0, /*y*/ 0, width, /*height*/ 1);
|
|
let mut buf = Buffer::empty(area);
|
|
content.render(area, &mut buf, StatusLineFocus::Focused);
|
|
assert_eq!(buf[(4, 0)].symbol(), " ");
|
|
for (x, ch) in (5..width).zip(visible_link.chars()) {
|
|
assert_eq!(buf[(x, 0)].symbol(), osc8_hyperlink(url, &ch.to_string()));
|
|
}
|
|
if width < 11 {
|
|
assert_eq!(buf[(width - 1, 0)].symbol(), "…");
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn prepared_tree_paints_only_the_footer_viewport() {
|
|
use crate::terminal_hyperlinks::strip_osc8;
|
|
use crate::ui_tree::UiTree;
|
|
use ratatui::buffer::Cell;
|
|
|
|
let url = "https://example.com/build";
|
|
let tree: UiTree = serde_json::json!({
|
|
"type":"link","props":{"href":url},"children":["ok\nlarge build\na\nb\nc\nd"]
|
|
})
|
|
.to_string()
|
|
.parse()
|
|
.unwrap();
|
|
let prepared = StatusLine::from(tree);
|
|
|
|
let area = Rect::new(
|
|
/*x*/ 1, /*y*/ 1, /*width*/ 6, /*height*/ 4,
|
|
);
|
|
let mut buffer = Buffer::filled(
|
|
Rect::new(
|
|
/*x*/ 0, /*y*/ 0, /*width*/ 8, /*height*/ 7,
|
|
),
|
|
Cell::new("."),
|
|
);
|
|
prepared.render(area, &mut buffer, StatusLineFocus::Focused);
|
|
let rows: Vec<String> = buffer
|
|
.content
|
|
.chunks(8)
|
|
.map(|row| row.iter().map(|cell| strip_osc8(cell.symbol())).collect())
|
|
.collect();
|
|
insta::assert_snapshot!(rows.join("\n"));
|
|
|
|
assert_eq!(buffer[(1, 4)].symbol(), osc8_hyperlink(url, "a"));
|
|
assert_eq!(buffer[(2, 4)].symbol(), "…");
|
|
}
|