| 514 | } |
| 515 | |
| 516 | func printDiffRecord(diff difflib.DiffRecord, to io.Writer) { |
| 517 | text := diff.Payload |
| 518 | |
| 519 | switch diff.Delta { |
| 520 | case difflib.RightOnly: |
| 521 | _, _ = fmt.Fprintf(to, "%s\n", ansi.Color("+ "+text, "green")) |
| 522 | case difflib.LeftOnly: |
| 523 | _, _ = fmt.Fprintf(to, "%s\n", ansi.Color("- "+text, "red")) |
| 524 | case difflib.Common: |
| 525 | if text == "" { |
| 526 | _, _ = fmt.Fprintln(to) |
| 527 | } else { |
| 528 | _, _ = fmt.Fprintf(to, "%s\n", " "+text) |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | // Calculate distance of every diff-line to the closest change |
| 534 | func calculateDistances(diffs []difflib.DiffRecord) map[int]int { |