Lightweight coding agent that runs in your terminal
Rust
Allow selecting and copying TUI turn tips (#53152)
Eric Traut41fd60f5618d
diff --git a/codex-rs/tui/src/app/owned_transcript.rs b/codex-rs/tui/src/app/owned_transcript.rsindex 744c2ed4ce..8c42d78f1c 100644--- a/codex-rs/tui/src/app/owned_transcript.rs+++ b/codex-rs/tui/src/app/owned_transcript.rs@@ -1,7 +1,7 @@//! Compose the owned transcript above the composer and route their selection gestures.//! Reserve a cleared row below activity and previews, immediately above the composer.//! Slash suggestions overlay already-painted rows so opening or closing them leaves transcript-//! geometry unchanged. Turn tips remain separate from selectable transcript text.+//! geometry unchanged. Turn tips remain outside transcript history; their painted rows are selectable.//! Plain Enter returns an empty composer to latest after transcript interactions and prompt editing.use super::turn_tips::TipSurface;@@ -97,7 +97,7 @@ impl App {.has_active_interaction(){Some(- ratatui::text::Line::from("Selecting footer · esc cancel")+ ratatui::text::Line::from("Selecting text · esc cancel").dim().into(),)@@ -194,6 +194,8 @@ impl App {);if let Some(gap) = composer_gap.as_mut() {gap.needs_separator = available > 1+ // Keep the tip under the pointer when selection hints or copy feedback appear.+ && turn_tip.is_none()&& chat_widget.no_modal_or_popup_active()&& view.composer_gap_has_content(transcript_width, composer_hint.as_ref(), now);}@@ -287,6 +289,14 @@ impl App {.filter(|_| chat_widget.no_modal_or_popup_active());feedback_tick =view.render_composer_gap(follow_area, composer_hint.as_ref(), frame.buffer, now);+ if let Some((_, tip)) = &turn_tip+ && let Some(area) = tip.rendered.get()+ {+ chat_widget+ .rendered_selection+ .borrow_mut()+ .register(area, /*invalidate*/ false);+ }chat_widget.rendered_selection.borrow_mut()@@ -313,7 +323,7 @@ impl App {}})?;if let Some((surface, tip)) = &turn_tip- && tip.rendered.get()+ && tip.rendered.get().is_some(){self.turn_tips.acknowledge(*surface);}diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__fullscreen_footer_selection.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__fullscreen_footer_selection.snapindex c609b9ff9d..eaa206c6bc 100644--- a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__fullscreen_footer_selection.snap+++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__fullscreen_footer_selection.snap@@ -1,6 +1,6 @@---source: tui/src/app/owned_transcript_tests.rs-assertion_line: 1545+assertion_line: 1831expression: "normalize_snapshot_paths(buffer_text(crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal)))"---@@ -21,7 +21,7 @@ expression: "normalize_snapshot_paths(buffer_text(crate::custom_terminal::test_s- Selecting footer · esc cancel+ Selecting text · esc cancel› draft stays herediff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__turn_tips__tests__turn_tip_placements.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__turn_tips__tests__turn_tip_placements.snapindex 71b29376ac..f6cfeee615 100644--- a/codex-rs/tui/src/app/snapshots/codex_tui__app__turn_tips__tests__turn_tip_placements.snap+++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__turn_tips__tests__turn_tip_placements.snap@@ -1,5 +1,6 @@---source: tui/src/app/turn_tips_tests.rs+assertion_line: 387expression: "crate::chatwidget::tests::helpers::normalize_snapshot_paths(screens.join(\"\\n\\n\"))"---working=true, response rows=1, 80x12@@ -33,6 +34,58 @@ working=false, response rows=1, 80x12Worked for [duration] • [completion time]+› Ask Codex to do anything++ gpt-test default · /tmp/project+ ? for shortcuts++working=false, response rows=1, 80x24++› Show a response.+++Response row 0++• Done.+ └ Tip: Try /help.++ Worked for [duration] • [completion time]+++++++++++› Ask Codex to do anything++ gpt-test default · /tmp/project+ ? for shortcuts++Completion tip selected, 80x24++› Show a response.+++Response row 0++• Done.+ └ Tip: Try /help.++ Worked for [duration] • [completion time]+++++++++ Copying 5 chars…+› Ask Codex to do anythinggpt-test default · /tmp/projectdiff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__turn_tips__tests__working_tip_selected.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__turn_tips__tests__working_tip_selected.snapnew file mode 100644index 0000000000..870b86f61c--- /dev/null+++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__turn_tips__tests__working_tip_selected.snap@@ -0,0 +1,29 @@+---+source: tui/src/app/turn_tips_tests.rs+assertion_line: 485+expression: "crate::chatwidget::tests::helpers::normalize_snapshot_paths(buffer_text(crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal),))"+---+Response row 0+Response row 1+Response row 2+Response row 3+Response row 4+Response row 5+Response row 6+Response row 7+Response row 8+Response row 9+++++++• Working (0s • esc to interrupt)+ └ Tip: Try /help.+ Copying 5 chars…++› Ask Codex to do anything++ gpt-test default · /tmp/project+ ? for shortcutsdiff --git a/codex-rs/tui/src/app/turn_tips_tests.rs b/codex-rs/tui/src/app/turn_tips_tests.rsindex 070cfe534a..8d79bdf06a 100644--- a/codex-rs/tui/src/app/turn_tips_tests.rs+++ b/codex-rs/tui/src/app/turn_tips_tests.rs@@ -190,6 +190,7 @@ async fn turn_tip_placements_and_completion_barrier() -> Result<()> {(true, 1, 80, 12),(true, 1, 80, 6),(false, 1, 80, 12),+ (false, 1, 80, 24),(false, 30, 80, 12),(false, 1, 80, 9),(false, 1, 80, 10),@@ -281,6 +282,44 @@ async fn turn_tip_placements_and_completion_barrier() -> Result<()> {assert_eq!(app.turn_tips.completions_shown, usize::from(!working));}if !working && shown {+ if rows == 1 && size == tui.terminal.size()? {+ app.local_settings.tui.copy_on_select = CopyOnSelect::Always;+ let (row, line) = screen+ .lines()+ .enumerate()+ .find(|(_, line)| line.contains("└ Tip:"))+ .unwrap();+ let column = line[..line.find("/help").unwrap()].chars().count() as u16;+ for (kind, column) in [+ (Down(Left), column),+ (Drag(Left), column + 5),+ (Up(Left), column + 5),+ ] {+ assert!(app.handle_rendered_selection_event(+ &mut tui,+ &TuiEvent::Mouse(MouseEvent {+ kind,+ column,+ row: row as u16,+ modifiers: KeyModifiers::NONE,+ }),+ )?);+ app.render_owned_transcript(&mut tui, size)?;+ }+ let mut selection = app.chat_widget.rendered_selection.borrow_mut();+ let crate::rendered_selection::RenderedSelection { view, cells, .. } =+ &mut *selection;+ assert_eq!(view.selected_text(cells), Some("/help".into()));+ screens.push(format!(+ "Completion tip selected, {width}x{height}\n{}",+ crate::chatwidget::tests::helpers::normalize_completion_timestamps(+ app.transcript_cells.last().unwrap().as_ref(),+ buffer_text(crate::custom_terminal::test_support::last_rendered_buffer(+ &tui.terminal,+ )),+ )+ ));+ }assert!(!app.transcript_cells.iter()@@ -448,6 +487,46 @@ async fn working_tip_stays_put_through_mouse_selection() -> Result<()> {app.transcript_view.selected_text(&app.transcript_cells),Some("ponse".into()),);+ // Start from the usual following viewport, without an existing transcript selection.+ app.transcript_view.jump_to_latest();+ app.local_settings.tui.copy_on_select = CopyOnSelect::Always;+ app.render_owned_transcript(&mut tui, size)?;+ let before = buffer_text(crate::custom_terminal::test_support::last_rendered_buffer(+ &tui.terminal,+ ));+ let (tip_row, tip_line) = before+ .lines()+ .enumerate()+ .find(|(_, line)| line.contains("└ Tip:"))+ .unwrap();+ let column = tip_line[..tip_line.find("/help").unwrap()].chars().count() as u16;+ for (kind, column) in [+ (Down(Left), column),+ (Drag(Left), column + 5),+ (Up(Left), column + 5),+ ] {+ assert!(app.handle_rendered_selection_event(+ &mut tui,+ &TuiEvent::Mouse(MouseEvent {+ kind,+ column,+ row: tip_row as u16,+ modifiers: KeyModifiers::NONE,+ }),+ )?);+ app.render_owned_transcript(&mut tui, size)?;+ }+ {+ let mut selection = app.chat_widget.rendered_selection.borrow_mut();+ let crate::rendered_selection::RenderedSelection { view, cells, .. } = &mut *selection;+ assert_eq!(view.selected_text(cells), Some("/help".into()));+ }+ insta::assert_snapshot!(+ "working_tip_selected",+ crate::chatwidget::tests::helpers::normalize_snapshot_paths(buffer_text(+ crate::custom_terminal::test_support::last_rendered_buffer(&tui.terminal),+ ))+ );app.transcript_view.jump_to_latest();app.chat_widget.on_rate_limit_snapshot(Some(serde_json::from_value(serde_json::json!({@@ -473,6 +552,11 @@ async fn working_tip_stays_put_through_mouse_selection() -> Result<()> {)).contains("└ Tip:"));+ {+ let mut selection = app.chat_widget.rendered_selection.borrow_mut();+ let crate::rendered_selection::RenderedSelection { view, cells, .. } = &mut *selection;+ assert_eq!(view.selected_text(cells), None);+ }server.shutdown().await?;tui.set_owned_screen(/*owned*/ false)?;Ok(())diff --git a/codex-rs/tui/src/turn_tip.rs b/codex-rs/tui/src/turn_tip.rsindex 2005a9a859..de437e3251 100644--- a/codex-rs/tui/src/turn_tip.rs+++ b/codex-rs/tui/src/turn_tip.rs@@ -14,15 +14,16 @@ use crate::terminal_hyperlinks::HyperlinkParagraph;pub(crate) struct TurnTip {pub(crate) line: HyperlinkLine,- pub(crate) rendered: Cell<bool>,+ pub(crate) rendered: Cell<Option<Rect>>,}impl Renderable for TurnTip {fn render(&self, area: Rect, buf: &mut Buffer) {if !area.is_empty() && self.line.width() <= usize::from(area.width) {+ let area = Rect { height: 1, ..area }.intersection(buf.area);HyperlinkParagraph::new(std::slice::from_ref(&self.line), Style::default())- .render(Rect { height: 1, ..area }, buf);- self.rendered.set(/*val*/ true);+ .render(area, buf);+ self.rendered.set(Some(area));}}