MCPcopy Create free account
hub / github.com/banga/git-split-diffs / iterFormatHunk

Function iterFormatHunk

src/iterFormatHunk.ts:17–49  ·  view source on GitHub ↗
(
    context: Context,
    diffType: 'unified-diff' | 'combined-diff',
    hunkHeaderLine: string,
    hunkParts: HunkPart[]
)

Source from the content-addressed store, hash-verified

15};
16
17export 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}

Callers 1

yieldHunkFunction · 0.90

Calls 7

iterFitTextToWidthFunction · 0.90
TFunction · 0.90
getChangesInLinesFunction · 0.90
iterFormatHunkSplitFunction · 0.90
appendStringMethod · 0.80

Tested by

no test coverage detected