MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / print_word_diff_line

Function print_word_diff_line

atomic-cli/src/commands/diff/output.rs:250–280  ·  view source on GitHub ↗

Format a diff stat line graph. Creates the +/- visual representation for stat output. # Arguments `insertions` - Number of insertions `deletions` - Number of deletions `max_width` - Maximum width for the graph # Returns A string containing + and - characters. Print a line with word-level diff highlighting. Uses ANSI escape codes to highlight changed tokens: - Deletions: bright red text on li

(
    content: &[u8],
    hunks: &[atomic_core::diff::ChangeHunk],
    is_deletion: bool,
)

Source from the content-addressed store, hash-verified

248/// Shared by the local unified renderer and the service-layer hook's
249/// word-diff render (one render, two data sources).
250pub(crate) fn print_word_diff_line(
251 content: &[u8],
252 hunks: &[atomic_core::diff::ChangeHunk],
253 is_deletion: bool,
254) {
255 for hunk in hunks {
256 if hunk.end > content.len() {
257 continue;
258 }
259 let text = String::from_utf8_lossy(&content[hunk.start..hunk.end]);
260
261 match hunk.kind {
262 HunkKind::Deleted | HunkKind::Modified if is_deletion => {
263 // Bright red text with underline for deletions
264 print!("\x1b[91;1;4m{}\x1b[0m", text);
265 }
266 HunkKind::Inserted | HunkKind::Modified if !is_deletion => {
267 // Bright green text with underline for insertions
268 print!("\x1b[92;1;4m{}\x1b[0m", text);
269 }
270 _ => {
271 // Normal text (unchanged parts)
272 if is_deletion {
273 print!("\x1b[31m{}\x1b[0m", text); // Dim red for context
274 } else {
275 print!("\x1b[32m{}\x1b[0m", text); // Dim green for context
276 }
277 }
278 }
279 }
280}
281
282/// Print a line with semantic token-level diff highlighting.
283///

Callers 2

print_word_diff_patchFunction · 0.85
print_unifiedMethod · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected