Render a Write tool as a block (file path + syntax-highlighted content preview)
(
tool_state: &ToolDisplayState,
theme: &Theme,
expanded: bool,
focused: bool,
spinner_frame: &str,
available_width: u16,
)
| 1212 | |
| 1213 | /// Render a Write tool as a block (file path + syntax-highlighted content preview) |
| 1214 | fn render_write_block( |
| 1215 | tool_state: &ToolDisplayState, |
| 1216 | theme: &Theme, |
| 1217 | expanded: bool, |
| 1218 | focused: bool, |
| 1219 | spinner_frame: &str, |
| 1220 | available_width: u16, |
| 1221 | ) -> ToolCardRenderOutput { |
| 1222 | let file_path = param_str( |
| 1223 | &tool_state.parameters, |
| 1224 | &["file_path", "target_file", "path"], |
| 1225 | ); |
| 1226 | |
| 1227 | let mut content_lines = Vec::new(); |
| 1228 | |
| 1229 | // Show content preview with syntax highlighting and line numbers |
| 1230 | if let Some(content) = tool_state |
| 1231 | .parameters |
| 1232 | .get("contents") |
| 1233 | .or_else(|| tool_state.parameters.get("content")) |
| 1234 | .and_then(|v| v.as_str()) |
| 1235 | { |
| 1236 | let total_lines = content.lines().count(); |
| 1237 | let max = if expanded { usize::MAX } else { 8 }; |
| 1238 | let ext = syntax_highlight::ext_from_path(&file_path); |
| 1239 | let hl_theme = HighlightTheme::Dark; // TODO: derive from theme |
| 1240 | |
| 1241 | // Use syntax highlighting with line numbers |
| 1242 | let highlighted = syntax_highlight::highlight_code_with_line_numbers( |
| 1243 | content, |
| 1244 | ext, |
| 1245 | hl_theme, |
| 1246 | theme.style(StyleKind::DiffLineNumber), |
| 1247 | theme.style(StyleKind::Muted), |
| 1248 | ); |
| 1249 | |
| 1250 | for line in highlighted.into_iter().take(max) { |
| 1251 | content_lines.push(line); |
| 1252 | } |
| 1253 | |
| 1254 | if total_lines > 8 && !expanded { |
| 1255 | content_lines.push(Line::from(Span::styled( |
| 1256 | format!( |
| 1257 | "\u{2026} ({} more lines, Ctrl+O to expand)", |
| 1258 | total_lines - 8 |
| 1259 | ), |
| 1260 | theme.style(StyleKind::Muted), |
| 1261 | ))); |
| 1262 | } else if expanded && total_lines > 8 { |
| 1263 | content_lines.push(Line::from(Span::styled( |
| 1264 | "Ctrl+O to collapse".to_string(), |
| 1265 | theme.style(StyleKind::Muted), |
| 1266 | ))); |
| 1267 | } |
| 1268 | |
| 1269 | // Title with line count |
| 1270 | let title = format!("Write {} ({} lines)", file_path, total_lines); |
| 1271 |
no test coverage detected