Print a line with highlighted hunks
(
content: &[u8],
hunks: &[atomic_core::diff::ChangeHunk],
is_deletion: bool,
)
| 94 | |
| 95 | /// Print a line with highlighted hunks |
| 96 | fn print_highlighted_line( |
| 97 | content: &[u8], |
| 98 | hunks: &[atomic_core::diff::ChangeHunk], |
| 99 | is_deletion: bool, |
| 100 | ) { |
| 101 | for hunk in hunks { |
| 102 | let text = String::from_utf8_lossy(&content[hunk.start..hunk.end]); |
| 103 | |
| 104 | match hunk.kind { |
| 105 | HunkKind::Deleted | HunkKind::Modified if is_deletion => { |
| 106 | // Dark red for deleted content |
| 107 | print!("\x1b[91;1m{}\x1b[0m", text); |
| 108 | } |
| 109 | HunkKind::Inserted | HunkKind::Modified if !is_deletion => { |
| 110 | // Dark green for inserted content |
| 111 | print!("\x1b[92;1m{}\x1b[0m", text); |
| 112 | } |
| 113 | _ => { |
| 114 | // Normal text (unchanged) |
| 115 | print!("{}", text); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /// Demonstrate multi-line diff with word-level highlighting |
| 122 | fn demo_multiline_diff() { |
no outgoing calls
no test coverage detected