Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Make banner URLs clickable across wrapped lines (#51452)

Charlie Marsh4b5c11134974
diff --git a/codex-rs/tui/src/bottom_pane/actionable_banner.rs b/codex-rs/tui/src/bottom_pane/actionable_banner.rs
index a7d7c327da..803adf86c6 100644
--- a/codex-rs/tui/src/bottom_pane/actionable_banner.rs
+++ b/codex-rs/tui/src/bottom_pane/actionable_banner.rs
@@ -13,7 +13,7 @@ use crate::render::RectExt;
use crate::render::renderable::Renderable;
use crate::terminal_palette::best_color;
use crate::terminal_palette::default_fg;
-use crate::wrapping::word_wrap_lines;
+use crate::wrapping::word_wrap_line_with_source;
use crossterm::event::KeyCode;
use crossterm::event::KeyEvent;
use crossterm::event::KeyEventKind;
@@ -21,9 +21,9 @@ use crossterm::event::KeyModifiers;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::Color;
+use ratatui::style::Style;
use ratatui::style::Stylize;
use ratatui::text::Line;
-use ratatui::widgets::Paragraph;
use ratatui::widgets::Widget;
use std::cell::Cell;
@@ -112,11 +112,19 @@ impl Renderable for InlineBanner {
struct BannerContent(Vec<Line<'static>>);
impl BannerContent {
- fn wrapped_lines(&self, width: u16) -> Vec<Line<'static>> {
- let mut lines = word_wrap_lines(&self.0, width as usize);
+ fn wrapped_lines(&self, width: u16) -> Vec<crate::terminal_hyperlinks::HyperlinkLine> {
+ let mut lines = crate::terminal_hyperlinks::annotate_web_urls(self.0.clone())
+ .into_iter()
+ .flat_map(|source| {
+ let wrapped = word_wrap_line_with_source(&source.line, usize::from(width));
+ crate::terminal_hyperlinks::remap_source_wrapped_line(&source, wrapped)
+ })
+ .collect::<Vec<_>>();
if lines.len() > 8 {
lines.truncate(7);
- lines.push("…".dim().into());
+ lines.push(crate::terminal_hyperlinks::HyperlinkLine::new(
+ "…".dim().into(),
+ ));
}
lines
}
@@ -127,7 +135,14 @@ impl Renderable for BannerContent {
let lines = self.wrapped_lines(area.width);
// Explicit foreground avoids a terminal's separate bold color washing out the title.
let foreground = default_fg().map(best_color).unwrap_or(Color::Reset);
- Widget::render(Paragraph::new(lines).fg(foreground), area, buf);
+ Widget::render(
+ crate::terminal_hyperlinks::HyperlinkParagraph::new(
+ &lines,
+ Style::default().fg(foreground),
+ ),
+ area,
+ buf,
+ );
}
fn desired_height(&self, width: u16) -> u16 {
diff --git a/codex-rs/tui/src/bottom_pane/tests/actionable_banner_tests.rs b/codex-rs/tui/src/bottom_pane/tests/actionable_banner_tests.rs
index 83ed170687..00e43a1040 100644
--- a/codex-rs/tui/src/bottom_pane/tests/actionable_banner_tests.rs
+++ b/codex-rs/tui/src/bottom_pane/tests/actionable_banner_tests.rs
@@ -258,3 +258,39 @@ fn information_banner_preserves_input_and_honors_dismissal() {
assert_eq!(pane.composer_text(), "1");
}
}
+
+#[test]
+fn banner_copy_preserves_wrapped_url_destinations() {
+ let url = "https://github.com/openai/codex/pull/12345?diff=split";
+ let (tx, _rx) = unbounded_channel();
+ let mut pane = test_pane(AppEventSender::new(tx));
+ pane.set_inline_banner(Some(ActionableBanner {
+ title: "Review the release".into(),
+ description: format!("Open {url} before continuing."),
+ ..Default::default()
+ }));
+ let area = Rect::new(0, 0, 40, pane.desired_height(/*width*/ 40));
+ let mut buf = ratatui::buffer::Buffer::empty(area);
+ pane.render(area, &mut buf);
+ let linked = buf
+ .content
+ .iter()
+ .filter(|cell| cell.symbol().contains("\x1b]8;;"))
+ .map(|cell| {
+ assert!(cell.symbol().starts_with(&format!("\x1b]8;;{url}\x07")));
+ crate::terminal_hyperlinks::strip_osc8(cell.symbol())
+ })
+ .collect::<String>();
+ assert_eq!(linked, url);
+ let visible = buf
+ .content
+ .chunks(usize::from(area.width))
+ .map(|row| {
+ row.iter()
+ .map(|cell| crate::terminal_hyperlinks::strip_osc8(cell.symbol()))
+ .collect::<String>()
+ })
+ .collect::<Vec<_>>()
+ .join("\n");
+ insta::assert_snapshot!("banner_wrapped_url", visible);
+}
diff --git a/codex-rs/tui/src/bottom_pane/tests/snapshots/codex_tui__bottom_pane__tests__actionable_banner_tests__banner_wrapped_url.snap b/codex-rs/tui/src/bottom_pane/tests/snapshots/codex_tui__bottom_pane__tests__actionable_banner_tests__banner_wrapped_url.snap
new file mode 100644
index 0000000000..01e6540e24
--- /dev/null
+++ b/codex-rs/tui/src/bottom_pane/tests/snapshots/codex_tui__bottom_pane__tests__actionable_banner_tests__banner_wrapped_url.snap
@@ -0,0 +1,16 @@
+---
+source: tui/src/bottom_pane/tests/actionable_banner_tests.rs
+expression: visible
+---
+
+ Review the release
+ Open https://github.com/openai/
+ codex/pull/12345?diff=split before
+ continuing.
+
+ esc to dismiss · type to continue
+
+
+› Ask Codex to do anything
+
+ ? for shortcuts 100% context left