* Print content diff with line-by-line changes.
(before: string | undefined, after: string | undefined, c: ChalkInstance)
| 374 | * Print content diff with line-by-line changes. |
| 375 | */ |
| 376 | function printContentDiff(before: string | undefined, after: string | undefined, c: ChalkInstance): void { |
| 377 | const oldContent = before ?? '' |
| 378 | const newContent = after ?? '' |
| 379 | |
| 380 | const changes = diffLines(oldContent, newContent) |
| 381 | |
| 382 | for (const change of changes) { |
| 383 | // Split into lines and remove trailing empty line from the split |
| 384 | const lines = change.value.split('\n') |
| 385 | if (lines[lines.length - 1] === '') { |
| 386 | lines.pop() |
| 387 | } |
| 388 | |
| 389 | for (const line of lines) { |
| 390 | if (change.added) { |
| 391 | output(c.green(` + ${line}`)) |
| 392 | } else if (change.removed) { |
| 393 | output(c.red(` - ${line}`)) |
| 394 | } else { |
| 395 | output(c.gray(` ${line}`)) |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | function getStatusIcon(status: 'added' | 'removed' | 'modified'): string { |
| 402 | if (status === 'added') return '+' |