mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
## What changed Render web URLs in selection labels and descriptions as terminal hyperlinks, preserving their complete destinations when text wraps or is truncated. Carry hyperlink ranges through two-column layouts and keep truncation ellipses outside links. ## Testing Add regression assertions and a snapshot covering wrapped and single-line rows, prefixed labels, descriptions, and wide Unicode characters. Verify that visible URL fragments retain complete destinations and ellipses are not linked. GitOrigin-RevId: 9d50b3ced79cbd29200e48a676445ec169d60758
92 lines
3.6 KiB
Rust
92 lines
3.6 KiB
Rust
use super::super::*;
|
|
|
|
#[test]
|
|
fn choice_labels_and_descriptions_keep_complete_url_destinations() {
|
|
let label = "https://github.com/openai/codex/pull/12345?diff=split";
|
|
let description = "https://example.com/releases/review/complete-destination";
|
|
let mut snapshots = Vec::new();
|
|
for prefix_label in [false, true] {
|
|
for wrap_indent in [Some(0), None] {
|
|
let mut row = GenericDisplayRow {
|
|
name: format!("日本語 {label}"),
|
|
description: Some(description.into()),
|
|
wrap_indent,
|
|
..Default::default()
|
|
};
|
|
if prefix_label {
|
|
row.name_prefix_spans = vec!["1. ".into(), std::mem::take(&mut row.name).bold()];
|
|
row.description = None;
|
|
}
|
|
let rows = [row];
|
|
for single_line in [false, true] {
|
|
let area = Rect::new(0, 0, 48, if single_line { 1 } else { 12 });
|
|
let mut buf = Buffer::empty(area);
|
|
if single_line {
|
|
render_rows_single_line_with_col_width_mode(
|
|
area,
|
|
&mut buf,
|
|
&rows,
|
|
&ScrollState::new(),
|
|
/*max_results*/ 1,
|
|
"",
|
|
ColumnWidthConfig::default(),
|
|
);
|
|
} else {
|
|
render_rows(
|
|
area,
|
|
&mut buf,
|
|
&rows,
|
|
&ScrollState::new(),
|
|
/*max_results*/ 1,
|
|
"",
|
|
);
|
|
}
|
|
let mut linked = 0;
|
|
for cell in &buf.content {
|
|
if cell.symbol().contains("\x1b]8;;") {
|
|
linked += 1;
|
|
assert!(
|
|
[label, description].iter().any(|url| cell
|
|
.symbol()
|
|
.starts_with(&format!("\x1b]8;;{url}\x07")))
|
|
);
|
|
assert_ne!(crate::terminal_hyperlinks::strip_osc8(cell.symbol()), "…");
|
|
}
|
|
}
|
|
assert!(linked > 0);
|
|
let urls = if prefix_label {
|
|
vec![label]
|
|
} else {
|
|
vec![label, description]
|
|
};
|
|
for url in urls {
|
|
let visible = buf
|
|
.content
|
|
.iter()
|
|
.filter(|cell| cell.symbol().starts_with(&format!("\x1b]8;;{url}\x07")))
|
|
.map(|cell| crate::terminal_hyperlinks::strip_osc8(cell.symbol()))
|
|
.collect::<String>();
|
|
assert!(!visible.is_empty() && url.starts_with(&visible));
|
|
}
|
|
let visible = buf
|
|
.content
|
|
.chunks(48)
|
|
.map(|row| {
|
|
row.iter()
|
|
.map(|cell| crate::terminal_hyperlinks::strip_osc8(cell.symbol()))
|
|
.collect::<String>()
|
|
.trim_end()
|
|
.to_owned()
|
|
})
|
|
.collect::<Vec<_>>()
|
|
.join("\n");
|
|
snapshots.push(format!(
|
|
"prefix label: {prefix_label}, wrapped label: {}, single line: {single_line}\n{visible}",
|
|
wrap_indent.is_some()
|
|
));
|
|
}
|
|
}
|
|
}
|
|
insta::assert_snapshot!("choice_wrapped_urls", snapshots.join("\n\n"));
|
|
}
|