(
context: Context,
diffType: 'unified-diff' | 'combined-diff',
hunkHeaderLine: string,
hunkParts: HunkPart[]
)
| 15 | }; |
| 16 | |
| 17 | export async function* iterFormatHunk( |
| 18 | context: Context, |
| 19 | diffType: 'unified-diff' | 'combined-diff', |
| 20 | hunkHeaderLine: string, |
| 21 | hunkParts: HunkPart[] |
| 22 | ): AsyncIterable<FormattedString> { |
| 23 | const { HUNK_HEADER_COLOR, SCREEN_WIDTH, MIN_LINE_WIDTH } = context; |
| 24 | |
| 25 | yield* iterFitTextToWidth( |
| 26 | context, |
| 27 | T().appendString(hunkHeaderLine), |
| 28 | SCREEN_WIDTH, |
| 29 | HUNK_HEADER_COLOR |
| 30 | ); |
| 31 | |
| 32 | // TODO: Fix to handle multiple hunk parts |
| 33 | const changes = getChangesInLines( |
| 34 | context, |
| 35 | hunkParts[0].lines, |
| 36 | hunkParts[1].lines |
| 37 | ); |
| 38 | |
| 39 | // Only split diffs if there's enough room |
| 40 | const splitDiffs = SCREEN_WIDTH >= MIN_LINE_WIDTH * hunkParts.length; |
| 41 | |
| 42 | if (splitDiffs) { |
| 43 | yield* iterFormatHunkSplit(context, hunkParts, changes); |
| 44 | } else if (diffType === 'unified-diff') { |
| 45 | yield* iterFormatUnifiedDiffHunkUnified(context, hunkParts, changes); |
| 46 | } else if (diffType === 'combined-diff') { |
| 47 | yield* iterFormatCombinedDiffHunkUnified(context, hunkParts, changes); |
| 48 | } |
| 49 | } |
no test coverage detected