mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Upgrade Ratatui to 0.30.2 (#35959)
## What changed - Upgrade `ratatui`, `ratatui-macros`, `crossterm`, and `ansi-to-tui`, and adapt the TUI to their updated rendering, backend, color-conversion, and cell APIs. - Use Ratatui's cell-width and continuation-cell metadata when mapping OSC 8 hyperlinks so links remain aligned across wrapped wide glyphs and halfwidth characters with dakuten. - Preserve explicit hyperlinks in the sign-in success screen and empty MCP state without embedding escape sequences in the text passed to Ratatui. ## Testing - Add regression coverage for hyperlink placement across wide glyphs and halfwidth dakuten, hyperlink preservation in onboarding and MCP output, and display-width handling. GitOrigin-RevId: 8460873e5a266923acd0417bc46264845eab0134
This commit is contained in:
1 parent
e1895710ad
commit
00cb5c465b
43 files changed
+1097
-303
No files matched your search
@@ -25,22 +25,28 @@ impl HistoryCell for PlainHistoryCell {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct WebHyperlinkHistoryCell {
|
||||
lines: Vec<Line<'static>>,
|
||||
lines: Vec<HyperlinkLine>,
|
||||
}
|
||||
|
||||
impl WebHyperlinkHistoryCell {
|
||||
pub(crate) fn new(lines: Vec<Line<'static>>) -> Self {
|
||||
Self {
|
||||
lines: crate::terminal_hyperlinks::annotate_web_urls(lines),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new_hyperlink_lines(lines: Vec<HyperlinkLine>) -> Self {
|
||||
Self { lines }
|
||||
}
|
||||
}
|
||||
|
||||
impl HistoryCell for WebHyperlinkHistoryCell {
|
||||
fn display_lines(&self, _width: u16) -> Vec<Line<'static>> {
|
||||
self.lines.clone()
|
||||
self.lines.iter().map(|line| line.line.clone()).collect()
|
||||
}
|
||||
|
||||
fn display_hyperlink_lines(&self, _width: u16) -> Vec<HyperlinkLine> {
|
||||
crate::terminal_hyperlinks::annotate_web_urls(self.lines.clone())
|
||||
self.lines.clone()
|
||||
}
|
||||
|
||||
fn transcript_hyperlink_lines(&self, width: u16) -> Vec<HyperlinkLine> {
|
||||
@@ -48,7 +54,7 @@ impl HistoryCell for WebHyperlinkHistoryCell {
|
||||
}
|
||||
|
||||
fn raw_lines(&self) -> Vec<Line<'static>> {
|
||||
plain_lines(self.lines.clone())
|
||||
plain_lines(self.lines.iter().map(|line| line.line.clone()))
|
||||
}
|
||||
}
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -317,26 +317,24 @@ fn decode_mcp_image(block: &serde_json::Value) -> Option<DynamicImage> {
|
||||
.ok()
|
||||
}
|
||||
/// Render a summary of configured MCP servers from the current `Config`.
|
||||
pub(crate) fn empty_mcp_output() -> PlainHistoryCell {
|
||||
let lines: Vec<Line<'static>> = vec![
|
||||
"/mcp".magenta().into(),
|
||||
"".into(),
|
||||
vec!["🔌 ".into(), "MCP Tools".bold()].into(),
|
||||
"".into(),
|
||||
" • No MCP servers configured.".italic().into(),
|
||||
Line::from(vec![
|
||||
" See the ".into(),
|
||||
crate::terminal_hyperlinks::osc8_hyperlink(
|
||||
"https://developers.openai.com/codex/mcp",
|
||||
"MCP docs",
|
||||
)
|
||||
.underlined(),
|
||||
" to configure them.".into(),
|
||||
])
|
||||
.style(Style::default().add_modifier(Modifier::DIM)),
|
||||
pub(crate) fn empty_mcp_output() -> WebHyperlinkHistoryCell {
|
||||
let mut docs_line = HyperlinkLine::new(Line::from(" See the "));
|
||||
docs_line.push_span(
|
||||
"MCP docs".underlined(),
|
||||
Some("https://developers.openai.com/codex/mcp"),
|
||||
);
|
||||
docs_line.push_span(" to configure them.".into(), /*destination*/ None);
|
||||
|
||||
let lines = vec![
|
||||
HyperlinkLine::new("/mcp".magenta().into()),
|
||||
HyperlinkLine::from(""),
|
||||
HyperlinkLine::new(vec!["🔌 ".into(), "MCP Tools".bold()].into()),
|
||||
HyperlinkLine::from(""),
|
||||
HyperlinkLine::new(" • No MCP servers configured.".italic().into()),
|
||||
docs_line.style(Style::default().add_modifier(Modifier::DIM)),
|
||||
];
|
||||
|
||||
PlainHistoryCell::new(lines)
|
||||
WebHyperlinkHistoryCell::new_hyperlink_lines(lines)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -257,22 +257,9 @@ pub(crate) trait HistoryCell: std::fmt::Debug + Send + Sync + Any {
|
||||
|
||||
/// Returns the number of viewport rows for the transcript overlay.
|
||||
///
|
||||
/// Uses the same `Paragraph::line_count` measurement as
|
||||
/// `desired_height`. Contains a workaround for a ratatui bug where
|
||||
/// a single whitespace-only line reports 2 rows instead of 1.
|
||||
/// Uses the same `Paragraph::line_count` measurement as `desired_height`.
|
||||
fn desired_transcript_height(&self, width: u16) -> u16 {
|
||||
let lines = visible_lines(self.transcript_hyperlink_lines(width));
|
||||
// Workaround: ratatui's line_count returns 2 for a single
|
||||
// whitespace-only line. Clamp to 1 in that case.
|
||||
if let [line] = &lines[..]
|
||||
&& line
|
||||
.spans
|
||||
.iter()
|
||||
.all(|s| s.content.chars().all(char::is_whitespace))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
Paragraph::new(Text::from(lines))
|
||||
.wrap(Wrap { trim: false })
|
||||
.line_count(width)
|
||||
|
||||
@@ -6,7 +6,7 @@ fn finalized_plan_reuses_lines_primed_by_transcript_height() {
|
||||
let cell = new_proposed_plan("1. Inspect **markdown**".to_string(), Path::new("/tmp"));
|
||||
let width = 48;
|
||||
|
||||
assert_eq!(cell.desired_transcript_height(width), 8);
|
||||
assert_eq!(cell.desired_transcript_height(width), 5);
|
||||
cell.rendered_lines
|
||||
.cached
|
||||
.lock()
|
||||
|
||||
@@ -352,6 +352,57 @@ fn composite_cell_preserves_child_web_links() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_mcp_output_preserves_docs_hyperlink() {
|
||||
let destination = "https://developers.openai.com/codex/mcp";
|
||||
let cell: Box<dyn HistoryCell> = Box::new(empty_mcp_output());
|
||||
|
||||
insta::assert_snapshot!(render_lines(&cell.display_lines(/*width*/ 80)).join("\n"), @r"
|
||||
/mcp
|
||||
|
||||
🔌 MCP Tools
|
||||
|
||||
• No MCP servers configured.
|
||||
See the MCP docs to configure them.
|
||||
");
|
||||
|
||||
let expected_link = vec![crate::terminal_hyperlinks::TerminalHyperlink::web(
|
||||
/*columns*/ 12..20,
|
||||
destination.to_string(),
|
||||
)];
|
||||
assert_eq!(
|
||||
cell.display_hyperlink_lines(/*width*/ 80)[5].hyperlinks,
|
||||
expected_link
|
||||
);
|
||||
assert_eq!(
|
||||
cell.transcript_hyperlink_lines(/*width*/ 80)[5].hyperlinks,
|
||||
expected_link
|
||||
);
|
||||
|
||||
let area = Rect::new(0, 0, 80, 6);
|
||||
let mut buf = Buffer::empty(area);
|
||||
cell.render(area, &mut buf);
|
||||
assert_eq!(
|
||||
(0..39).map(|x| buf[(x, 5)].modifier).collect::<Vec<_>>(),
|
||||
[
|
||||
vec![Modifier::DIM; 12],
|
||||
vec![Modifier::DIM | Modifier::UNDERLINED; 8],
|
||||
vec![Modifier::DIM; 19],
|
||||
]
|
||||
.concat()
|
||||
);
|
||||
let linked_text = area
|
||||
.positions()
|
||||
.filter_map(|position| {
|
||||
let symbol = buf[position].symbol();
|
||||
symbol
|
||||
.contains(&format!("\x1b]8;;{destination}\x07"))
|
||||
.then(|| crate::terminal_hyperlinks::strip_osc8(symbol))
|
||||
})
|
||||
.collect::<String>();
|
||||
assert_eq!(linked_text, "MCP docs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn proposed_plan_cell_unwraps_markdown_fenced_table() {
|
||||
let plan = new_proposed_plan(
|
||||
|
||||
Reference in new issue
Block a user