mirror of
https://github.com/openai/codex.git
synced 2026-04-24 22:54:54 +00:00
tui: improve rendering of search cell (#8273)
before: <img width="795" height="150" alt="Screenshot 2025-12-18 at 10 48 01 AM" src="https://github.com/user-attachments/assets/6f4d8856-b4c2-4e2a-b60a-b86f82b956a0" /> after: <img width="795" height="150" alt="Screenshot 2025-12-18 at 10 48 39 AM" src="https://github.com/user-attachments/assets/dd0d167a-5d09-4bb7-9d36-95a2eb1aaa83" />
This commit is contained in:
@@ -977,10 +977,7 @@ impl ChatWidget {
|
|||||||
|
|
||||||
fn on_web_search_end(&mut self, ev: WebSearchEndEvent) {
|
fn on_web_search_end(&mut self, ev: WebSearchEndEvent) {
|
||||||
self.flush_answer_stream_with_separator();
|
self.flush_answer_stream_with_separator();
|
||||||
self.add_to_history(history_cell::new_web_search_call(format!(
|
self.add_to_history(history_cell::new_web_search_call(ev.query));
|
||||||
"Searched: {}",
|
|
||||||
ev.query
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_get_history_entry_response(
|
fn on_get_history_entry_response(
|
||||||
|
|||||||
@@ -1087,9 +1087,9 @@ pub(crate) fn new_active_mcp_tool_call(
|
|||||||
McpToolCallCell::new(call_id, invocation, animations_enabled)
|
McpToolCallCell::new(call_id, invocation, animations_enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_web_search_call(query: String) -> PlainHistoryCell {
|
pub(crate) fn new_web_search_call(query: String) -> PrefixedWrappedHistoryCell {
|
||||||
let lines: Vec<Line<'static>> = vec![Line::from(vec![padded_emoji("🌐").into(), query.into()])];
|
let text: Text<'static> = Line::from(vec!["Searched".bold(), " ".into(), query.into()]).into();
|
||||||
PlainHistoryCell { lines }
|
PrefixedWrappedHistoryCell::new(text, "• ".dim(), " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the first content is an image, return a new cell with the image.
|
/// 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]
|
#[test]
|
||||||
fn active_mcp_tool_call_snapshot() {
|
fn active_mcp_tool_call_snapshot() {
|
||||||
let invocation = McpInvocation {
|
let invocation = McpInvocation {
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
source: tui/src/history_cell.rs
|
||||||
|
expression: rendered
|
||||||
|
---
|
||||||
|
• Searched example search query with several generic words to
|
||||||
|
exercise wrapping
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
source: tui/src/history_cell.rs
|
||||||
|
expression: rendered
|
||||||
|
---
|
||||||
|
• Searched example search query with several generic words to
|
||||||
|
exercise wrapping
|
||||||
@@ -891,10 +891,7 @@ impl ChatWidget {
|
|||||||
|
|
||||||
fn on_web_search_end(&mut self, ev: WebSearchEndEvent) {
|
fn on_web_search_end(&mut self, ev: WebSearchEndEvent) {
|
||||||
self.flush_answer_stream_with_separator();
|
self.flush_answer_stream_with_separator();
|
||||||
self.add_to_history(history_cell::new_web_search_call(format!(
|
self.add_to_history(history_cell::new_web_search_call(ev.query));
|
||||||
"Searched: {}",
|
|
||||||
ev.query
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_get_history_entry_response(
|
fn on_get_history_entry_response(
|
||||||
|
|||||||
@@ -1021,9 +1021,9 @@ pub(crate) fn new_active_mcp_tool_call(
|
|||||||
McpToolCallCell::new(call_id, invocation, animations_enabled)
|
McpToolCallCell::new(call_id, invocation, animations_enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_web_search_call(query: String) -> PlainHistoryCell {
|
pub(crate) fn new_web_search_call(query: String) -> PrefixedWrappedHistoryCell {
|
||||||
let lines: Vec<Line<'static>> = vec![Line::from(vec![padded_emoji("🌐").into(), query.into()])];
|
let text: Text<'static> = Line::from(vec!["Searched".bold(), " ".into(), query.into()]).into();
|
||||||
PlainHistoryCell { lines }
|
PrefixedWrappedHistoryCell::new(text, "• ".dim(), " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the first content is an image, return a new cell with the image.
|
/// 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]
|
#[test]
|
||||||
fn active_mcp_tool_call_snapshot() {
|
fn active_mcp_tool_call_snapshot() {
|
||||||
let invocation = McpInvocation {
|
let invocation = McpInvocation {
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
source: tui2/src/history_cell.rs
|
||||||
|
expression: rendered
|
||||||
|
---
|
||||||
|
• Searched example search query with several generic words to
|
||||||
|
exercise wrapping
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
source: tui2/src/history_cell.rs
|
||||||
|
expression: rendered
|
||||||
|
---
|
||||||
|
• Searched example search query with several generic words to
|
||||||
|
exercise wrapping
|
||||||
Reference in New Issue
Block a user