Lightweight coding agent that runs in your terminal
Rust
tui: improve rendering of search cell (#8273)
Jeremy Rosebe274cbe6273
diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rsindex f38bcd783a..be4efd2c7a 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.rsindex 2c0a37ecea..a8c37d0f85 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<Line<'static>> = 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.snapnew file mode 100644index 0000000000..e119420f18--- /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 wrappingdiff --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.snapnew file mode 100644index 0000000000..e119420f18--- /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 wrappingdiff --git a/codex-rs/tui2/src/chatwidget.rs b/codex-rs/tui2/src/chatwidget.rsindex 62d026d61c..a612b8da1e 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.rsindex 5440040f6b..f21d56b5cb 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<Line<'static>> = 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.snapnew file mode 100644index 0000000000..5b365e3178--- /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 wrappingdiff --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.snapnew file mode 100644index 0000000000..5b365e3178--- /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