Render a tool card. Returns a list of ListItems for the chat message list. Parameters: - `tool_state`: current tool display state - `theme`: UI theme - `expanded`: whether this block tool is expanded (for output truncation) - `focused`: whether this tool card is currently focused (for border highlight) - `spinner_frame`: current spinner animation frame (for running tools) - `available_width`: ter
(
tool_state: &ToolDisplayState,
theme: &Theme,
expanded: bool,
focused: bool,
spinner_frame: &str,
available_width: u16,
)
| 159 | /// - `spinner_frame`: current spinner animation frame (for running tools) |
| 160 | /// - `available_width`: terminal width available for rendering (for split diff) |
| 161 | pub fn render_tool_card( |
| 162 | tool_state: &ToolDisplayState, |
| 163 | theme: &Theme, |
| 164 | expanded: bool, |
| 165 | focused: bool, |
| 166 | spinner_frame: &str, |
| 167 | available_width: u16, |
| 168 | ) -> ToolCardRenderOutput { |
| 169 | // Check cache for completed tools |
| 170 | if is_terminal_status(&tool_state.status) { |
| 171 | let key = ToolCardCacheKey { |
| 172 | tool_id: tool_state.tool_id.clone(), |
| 173 | expanded, |
| 174 | focused, |
| 175 | width: available_width, |
| 176 | }; |
| 177 | let cached = TOOL_CARD_CACHE.with(|cache| cache.borrow().get(&key).cloned()); |
| 178 | if let Some(rendered) = cached { |
| 179 | return rendered; |
| 180 | } |
| 181 | |
| 182 | // Render and cache |
| 183 | let rendered = render_tool_card_inner( |
| 184 | tool_state, |
| 185 | theme, |
| 186 | expanded, |
| 187 | focused, |
| 188 | spinner_frame, |
| 189 | available_width, |
| 190 | ); |
| 191 | let rendered_clone = rendered.clone(); |
| 192 | TOOL_CARD_CACHE.with(|cache| { |
| 193 | cache.borrow_mut().insert(key, rendered_clone); |
| 194 | }); |
| 195 | return rendered; |
| 196 | } |
| 197 | |
| 198 | // Non-terminal tools: render without caching |
| 199 | render_tool_card_inner( |
| 200 | tool_state, |
| 201 | theme, |
| 202 | expanded, |
| 203 | focused, |
| 204 | spinner_frame, |
| 205 | available_width, |
| 206 | ) |
| 207 | } |
| 208 | |
| 209 | /// Internal render function (no caching) |
| 210 | fn render_tool_card_inner( |
no test coverage detected