Internal helper to render content with ANSI codes.
(&self, content: &[u8], hunks: &[ChangeHunk], is_old: bool)
| 495 | |
| 496 | /// Internal helper to render content with ANSI codes. |
| 497 | fn render_with_ansi(&self, content: &[u8], hunks: &[ChangeHunk], is_old: bool) -> String { |
| 498 | let mut result = String::new(); |
| 499 | |
| 500 | for hunk in hunks { |
| 501 | let text = String::from_utf8_lossy(hunk.extract(content)); |
| 502 | |
| 503 | if hunk.is_change() { |
| 504 | let color = if is_old { |
| 505 | "\x1b[91m" // Bright red for deletions |
| 506 | } else { |
| 507 | "\x1b[92m" // Bright green for insertions |
| 508 | }; |
| 509 | result.push_str(color); |
| 510 | result.push_str(&text); |
| 511 | result.push_str(HunkKind::ansi_reset()); |
| 512 | } else { |
| 513 | result.push_str(&text); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | result |
| 518 | } |
| 519 | |
| 520 | /// Render the old line with HTML highlighting. |
| 521 | /// |
no test coverage detected