MCPcopy Create free account
hub / github.com/GCWing/BitFun / render_write_block

Function render_write_block

src/apps/cli/src/ui/tool_cards.rs:1214–1335  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

1212
1213/// Render a Write tool as a block (file path + syntax-highlighted content preview)
1214fn 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

Callers 1

render_block_dispatchFunction · 0.85

Calls 13

param_strFunction · 0.85
ext_from_pathFunction · 0.85
block_content_max_widthFunction · 0.85
wrap_display_linesFunction · 0.85
assemble_blockFunction · 0.85
styleMethod · 0.80
takeMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45
countMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected