From be274cbe6273cb17d756a6cda729d537f15ae49a Mon Sep 17 00:00:00 2001 From: Jeremy Rose <172423086+nornagon-openai@users.noreply.github.com> Date: Thu, 18 Dec 2025 11:05:26 -0800 Subject: [PATCH] tui: improve rendering of search cell (#8273) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit before: Screenshot 2025-12-18 at 10 48 01 AM after: Screenshot 2025-12-18 at 10 48 39 AM --- codex-rs/tui/src/chatwidget.rs | 5 +- codex-rs/tui/src/history_cell.rs | 50 +++++++++++++++++-- ...sts__web_search_history_cell_snapshot.snap | 6 +++ ...arch_history_cell_transcript_snapshot.snap | 6 +++ codex-rs/tui2/src/chatwidget.rs | 5 +- codex-rs/tui2/src/history_cell.rs | 50 +++++++++++++++++-- ...sts__web_search_history_cell_snapshot.snap | 6 +++ ...arch_history_cell_transcript_snapshot.snap | 6 +++ 8 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 codex-rs/tui/src/snapshots/codex_tui__history_cell__tests__web_search_history_cell_snapshot.snap create mode 100644 codex-rs/tui/src/snapshots/codex_tui__history_cell__tests__web_search_history_cell_transcript_snapshot.snap create mode 100644 codex-rs/tui2/src/snapshots/codex_tui2__history_cell__tests__web_search_history_cell_snapshot.snap create mode 100644 codex-rs/tui2/src/snapshots/codex_tui2__history_cell__tests__web_search_history_cell_transcript_snapshot.snap diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index f38bcd783..be4efd2c7 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -977,10 +977,7 @@ impl ChatWidget { fn on_web_search_end(&mut self, ev: WebSearchEndEvent) { self.flush_answer_stream_with_separator(); - self.add_to_history(history_cell::new_web_search_call(format!( - "Searched: {}", - ev.query - ))); + self.add_to_history(history_cell::new_web_search_call(ev.query)); } fn on_get_history_entry_response( diff --git a/codex-rs/tui/src/history_cell.rs b/codex-rs/tui/src/history_cell.rs index 2c0a37ece..a8c37d0f8 100644 --- a/codex-rs/tui/src/history_cell.rs +++ b/codex-rs/tui/src/history_cell.rs @@ -1087,9 +1087,9 @@ pub(crate) fn new_active_mcp_tool_call( McpToolCallCell::new(call_id, invocation, animations_enabled) } -pub(crate) fn new_web_search_call(query: String) -> PlainHistoryCell { - let lines: Vec> = vec![Line::from(vec![padded_emoji("🌐").into(), query.into()])]; - PlainHistoryCell { lines } +pub(crate) fn new_web_search_call(query: String) -> PrefixedWrappedHistoryCell { + let text: Text<'static> = Line::from(vec!["Searched".bold(), " ".into(), query.into()]).into(); + PrefixedWrappedHistoryCell::new(text, "• ".dim(), " ") } /// If the first content is an image, return a new cell with the image. @@ -1764,6 +1764,50 @@ mod tests { ); } + #[test] + fn web_search_history_cell_snapshot() { + let cell = new_web_search_call( + "example search query with several generic words to exercise wrapping".to_string(), + ); + let rendered = render_lines(&cell.display_lines(64)).join("\n"); + + insta::assert_snapshot!(rendered); + } + + #[test] + fn web_search_history_cell_wraps_with_indented_continuation() { + let cell = new_web_search_call( + "example search query with several generic words to exercise wrapping".to_string(), + ); + let rendered = render_lines(&cell.display_lines(64)); + + assert_eq!( + rendered, + vec![ + "• Searched example search query with several generic words to".to_string(), + " exercise wrapping".to_string(), + ] + ); + } + + #[test] + fn web_search_history_cell_short_query_does_not_wrap() { + let cell = new_web_search_call("short query".to_string()); + let rendered = render_lines(&cell.display_lines(64)); + + assert_eq!(rendered, vec!["• Searched short query".to_string()]); + } + + #[test] + fn web_search_history_cell_transcript_snapshot() { + let cell = new_web_search_call( + "example search query with several generic words to exercise wrapping".to_string(), + ); + let rendered = render_lines(&cell.transcript_lines(64)).join("\n"); + + insta::assert_snapshot!(rendered); + } + #[test] fn active_mcp_tool_call_snapshot() { let invocation = McpInvocation { diff --git a/codex-rs/tui/src/snapshots/codex_tui__history_cell__tests__web_search_history_cell_snapshot.snap b/codex-rs/tui/src/snapshots/codex_tui__history_cell__tests__web_search_history_cell_snapshot.snap new file mode 100644 index 000000000..e119420f1 --- /dev/null +++ b/codex-rs/tui/src/snapshots/codex_tui__history_cell__tests__web_search_history_cell_snapshot.snap @@ -0,0 +1,6 @@ +--- +source: tui/src/history_cell.rs +expression: rendered +--- +• Searched example search query with several generic words to + exercise wrapping diff --git a/codex-rs/tui/src/snapshots/codex_tui__history_cell__tests__web_search_history_cell_transcript_snapshot.snap b/codex-rs/tui/src/snapshots/codex_tui__history_cell__tests__web_search_history_cell_transcript_snapshot.snap new file mode 100644 index 000000000..e119420f1 --- /dev/null +++ b/codex-rs/tui/src/snapshots/codex_tui__history_cell__tests__web_search_history_cell_transcript_snapshot.snap @@ -0,0 +1,6 @@ +--- +source: tui/src/history_cell.rs +expression: rendered +--- +• Searched example search query with several generic words to + exercise wrapping diff --git a/codex-rs/tui2/src/chatwidget.rs b/codex-rs/tui2/src/chatwidget.rs index 62d026d61..a612b8da1 100644 --- a/codex-rs/tui2/src/chatwidget.rs +++ b/codex-rs/tui2/src/chatwidget.rs @@ -891,10 +891,7 @@ impl ChatWidget { fn on_web_search_end(&mut self, ev: WebSearchEndEvent) { self.flush_answer_stream_with_separator(); - self.add_to_history(history_cell::new_web_search_call(format!( - "Searched: {}", - ev.query - ))); + self.add_to_history(history_cell::new_web_search_call(ev.query)); } fn on_get_history_entry_response( diff --git a/codex-rs/tui2/src/history_cell.rs b/codex-rs/tui2/src/history_cell.rs index 5440040f6..f21d56b5c 100644 --- a/codex-rs/tui2/src/history_cell.rs +++ b/codex-rs/tui2/src/history_cell.rs @@ -1021,9 +1021,9 @@ pub(crate) fn new_active_mcp_tool_call( McpToolCallCell::new(call_id, invocation, animations_enabled) } -pub(crate) fn new_web_search_call(query: String) -> PlainHistoryCell { - let lines: Vec> = vec![Line::from(vec![padded_emoji("🌐").into(), query.into()])]; - PlainHistoryCell { lines } +pub(crate) fn new_web_search_call(query: String) -> PrefixedWrappedHistoryCell { + let text: Text<'static> = Line::from(vec!["Searched".bold(), " ".into(), query.into()]).into(); + PrefixedWrappedHistoryCell::new(text, "• ".dim(), " ") } /// If the first content is an image, return a new cell with the image. @@ -1673,6 +1673,50 @@ mod tests { ); } + #[test] + fn web_search_history_cell_snapshot() { + let cell = new_web_search_call( + "example search query with several generic words to exercise wrapping".to_string(), + ); + let rendered = render_lines(&cell.display_lines(64)).join("\n"); + + insta::assert_snapshot!(rendered); + } + + #[test] + fn web_search_history_cell_wraps_with_indented_continuation() { + let cell = new_web_search_call( + "example search query with several generic words to exercise wrapping".to_string(), + ); + let rendered = render_lines(&cell.display_lines(64)); + + assert_eq!( + rendered, + vec![ + "• Searched example search query with several generic words to".to_string(), + " exercise wrapping".to_string(), + ] + ); + } + + #[test] + fn web_search_history_cell_short_query_does_not_wrap() { + let cell = new_web_search_call("short query".to_string()); + let rendered = render_lines(&cell.display_lines(64)); + + assert_eq!(rendered, vec!["• Searched short query".to_string()]); + } + + #[test] + fn web_search_history_cell_transcript_snapshot() { + let cell = new_web_search_call( + "example search query with several generic words to exercise wrapping".to_string(), + ); + let rendered = render_lines(&cell.transcript_lines(64)).join("\n"); + + insta::assert_snapshot!(rendered); + } + #[test] fn active_mcp_tool_call_snapshot() { let invocation = McpInvocation { diff --git a/codex-rs/tui2/src/snapshots/codex_tui2__history_cell__tests__web_search_history_cell_snapshot.snap b/codex-rs/tui2/src/snapshots/codex_tui2__history_cell__tests__web_search_history_cell_snapshot.snap new file mode 100644 index 000000000..5b365e317 --- /dev/null +++ b/codex-rs/tui2/src/snapshots/codex_tui2__history_cell__tests__web_search_history_cell_snapshot.snap @@ -0,0 +1,6 @@ +--- +source: tui2/src/history_cell.rs +expression: rendered +--- +• Searched example search query with several generic words to + exercise wrapping diff --git a/codex-rs/tui2/src/snapshots/codex_tui2__history_cell__tests__web_search_history_cell_transcript_snapshot.snap b/codex-rs/tui2/src/snapshots/codex_tui2__history_cell__tests__web_search_history_cell_transcript_snapshot.snap new file mode 100644 index 000000000..5b365e317 --- /dev/null +++ b/codex-rs/tui2/src/snapshots/codex_tui2__history_cell__tests__web_search_history_cell_transcript_snapshot.snap @@ -0,0 +1,6 @@ +--- +source: tui2/src/history_cell.rs +expression: rendered +--- +• Searched example search query with several generic words to + exercise wrapping