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

Function demo_inline_diff

atomic-core/examples/word_diff_demo.rs:70–93  ·  view source on GitHub ↗

Demonstrate inline diff between two lines

(title: &str, old: &[u8], new: &[u8])

Source from the content-addressed store, hash-verified

68
69/// Demonstrate inline diff between two lines
70fn demo_inline_diff(title: &str, old: &[u8], new: &[u8]) {
71 println!("┌─ {} ─┐", title);
72 println!("│");
73
74 let diff = compute_inline_diff(old, new);
75
76 // Render old line with deletions highlighted
77 print!("│ \x1b[101m - \x1b[0m "); // Light red background for line prefix
78 print_highlighted_line(old, diff.old_hunks(), true);
79 println!();
80
81 // Render new line with insertions highlighted
82 print!("│ \x1b[102m + \x1b[0m "); // Light green background for line prefix
83 print_highlighted_line(new, diff.new_hunks(), false);
84 println!();
85
86 println!("│");
87 println!(
88 "│ Stats: {} bytes deleted, {} bytes inserted",
89 diff.deleted_bytes(),
90 diff.inserted_bytes()
91 );
92 println!("└────────────────────────────────────────────────────────────────────┘\n");
93}
94
95/// Print a line with highlighted hunks
96fn print_highlighted_line(

Callers 1

mainFunction · 0.85

Calls 4

compute_inline_diffFunction · 0.85
print_highlighted_lineFunction · 0.85
old_hunksMethod · 0.80
new_hunksMethod · 0.80

Tested by

no test coverage detected