Demonstrate inline diff between two lines
(title: &str, old: &[u8], new: &[u8])
| 68 | |
| 69 | /// Demonstrate inline diff between two lines |
| 70 | fn 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 |
| 96 | fn print_highlighted_line( |
no test coverage detected