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:247–277  ·  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

245/// - Deletions: bright red text on light red background
246/// - Insertions: bright green text on light green background
247pub(super) fn print_word_diff_line(
248 content: &[u8],
249 hunks: &[atomic_core::diff::ChangeHunk],
250 is_deletion: bool,
251) {
252 for hunk in hunks {
253 if hunk.end > content.len() {
254 continue;
255 }
256 let text = String::from_utf8_lossy(&content[hunk.start..hunk.end]);
257
258 match hunk.kind {
259 HunkKind::Deleted | HunkKind::Modified if is_deletion => {
260 // Bright red text with underline for deletions
261 print!("\x1b[91;1;4m{}\x1b[0m", text);
262 }
263 HunkKind::Inserted | HunkKind::Modified if !is_deletion => {
264 // Bright green text with underline for insertions
265 print!("\x1b[92;1;4m{}\x1b[0m", text);
266 }
267 _ => {
268 // Normal text (unchanged parts)
269 if is_deletion {
270 print!("\x1b[31m{}\x1b[0m", text); // Dim red for context
271 } else {
272 print!("\x1b[32m{}\x1b[0m", text); // Dim green for context
273 }
274 }
275 }
276 }
277}
278
279/// Print a line with semantic token-level diff highlighting.
280///

Callers 1

print_unifiedMethod · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected