| 43 | }; |
| 44 | |
| 45 | const printAnnotation = ( |
| 46 | { |
| 47 | aAnnotation, |
| 48 | aColor, |
| 49 | aIndicator, |
| 50 | bAnnotation, |
| 51 | bColor, |
| 52 | bIndicator, |
| 53 | includeChangeCounts, |
| 54 | omitAnnotationLines, |
| 55 | }: DiffOptionsNormalized, |
| 56 | changeCounts: ChangeCounts, |
| 57 | ): string => { |
| 58 | if (omitAnnotationLines) { |
| 59 | return ''; |
| 60 | } |
| 61 | |
| 62 | let aRest = ''; |
| 63 | let bRest = ''; |
| 64 | |
| 65 | if (includeChangeCounts) { |
| 66 | const aCount = String(changeCounts.a); |
| 67 | const bCount = String(changeCounts.b); |
| 68 | |
| 69 | // Padding right aligns the ends of the annotations. |
| 70 | const baAnnotationLengthDiff = bAnnotation.length - aAnnotation.length; |
| 71 | const aAnnotationPadding = ' '.repeat(Math.max(0, baAnnotationLengthDiff)); |
| 72 | const bAnnotationPadding = ' '.repeat(Math.max(0, -baAnnotationLengthDiff)); |
| 73 | |
| 74 | // Padding left aligns the ends of the counts. |
| 75 | const baCountLengthDiff = bCount.length - aCount.length; |
| 76 | const aCountPadding = ' '.repeat(Math.max(0, baCountLengthDiff)); |
| 77 | const bCountPadding = ' '.repeat(Math.max(0, -baCountLengthDiff)); |
| 78 | |
| 79 | aRest = `${aAnnotationPadding} ${aIndicator} ${aCountPadding}${aCount}`; |
| 80 | bRest = `${bAnnotationPadding} ${bIndicator} ${bCountPadding}${bCount}`; |
| 81 | } |
| 82 | |
| 83 | const a = `${aIndicator} ${aAnnotation}${aRest}`; |
| 84 | const b = `${bIndicator} ${bAnnotation}${bRest}`; |
| 85 | return `${aColor(a)}\n${bColor(b)}\n\n`; |
| 86 | }; |
| 87 | |
| 88 | export const printDiffLines = ( |
| 89 | diffs: Array<Diff>, |