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

Function print_highlighted_line

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

Print a line with highlighted hunks

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

Source from the content-addressed store, hash-verified

94
95/// Print a line with highlighted hunks
96fn 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
122fn demo_multiline_diff() {

Callers 2

demo_inline_diffFunction · 0.85
demo_multiline_diffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected