(lines: SnapshotDiffLine[], contextWindow: number)
| 575 | } |
| 576 | |
| 577 | function applyContextWindow(lines: SnapshotDiffLine[], contextWindow: number): SnapshotDiffLine[] { |
| 578 | if (lines.length === 0) return lines; |
| 579 | const changedIndices = lines |
| 580 | .map((line, index) => ({ index, kind: line.kind })) |
| 581 | .filter((entry) => entry.kind === 'added' || entry.kind === 'removed') |
| 582 | .map((entry) => entry.index); |
| 583 | if (changedIndices.length === 0) return lines; |
| 584 | |
| 585 | const keep = new Array<boolean>(lines.length).fill(false); |
| 586 | for (const index of changedIndices) { |
| 587 | const start = Math.max(0, index - contextWindow); |
| 588 | const end = Math.min(lines.length - 1, index + contextWindow); |
| 589 | for (let i = start; i <= end; i += 1) { |
| 590 | keep[i] = true; |
| 591 | } |
| 592 | } |
| 593 | return lines.filter((_, index) => keep[index]); |
| 594 | } |
| 595 | |
| 596 | export function supportsColor(stream: { isTTY?: boolean } = process.stdout): boolean { |
| 597 | const forceColor = process.env.FORCE_COLOR; |
no test coverage detected