File size: 6,787 Bytes
39e315a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import { c as _c } from "react-compiler-runtime";
import type { StructuredPatchHunk } from 'diff';
import { resolve } from 'path';
import React, { useMemo } from 'react';
import { useTerminalSize } from '../../hooks/useTerminalSize.js';
import { Box, Text } from '../../ink.js';
import { getCwd } from '../../utils/cwd.js';
import { readFileSafe } from '../../utils/file.js';
import { Divider } from '../design-system/Divider.js';
import { StructuredDiff } from '../StructuredDiff.js';
type Props = {
  filePath: string;
  hunks: StructuredPatchHunk[];
  isLargeFile?: boolean;
  isBinary?: boolean;
  isTruncated?: boolean;
  isUntracked?: boolean;
};

/**
 * Displays the diff content for a single file.
 * Uses StructuredDiff for word-level diffing and syntax highlighting.
 * No scrolling - renders all lines (max 400 due to parsing limits).
 */
export function DiffDetailView(t0) {
  const $ = _c(53);
  const {
    filePath,
    hunks,
    isLargeFile,
    isBinary,
    isTruncated,
    isUntracked
  } = t0;
  const {
    columns
  } = useTerminalSize();
  let t1;
  bb0: {
    if (!filePath) {
      let t2;
      if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
        t2 = {
          firstLine: null,
          fileContent: undefined
        };
        $[0] = t2;
      } else {
        t2 = $[0];
      }
      t1 = t2;
      break bb0;
    }
    let content;
    let t2;
    if ($[1] !== filePath) {
      const fullPath = resolve(getCwd(), filePath);
      content = readFileSafe(fullPath);
      t2 = content?.split("\n")[0] ?? null;
      $[1] = filePath;
      $[2] = content;
      $[3] = t2;
    } else {
      content = $[2];
      t2 = $[3];
    }
    const t3 = content ?? undefined;
    let t4;
    if ($[4] !== t2 || $[5] !== t3) {
      t4 = {
        firstLine: t2,
        fileContent: t3
      };
      $[4] = t2;
      $[5] = t3;
      $[6] = t4;
    } else {
      t4 = $[6];
    }
    t1 = t4;
  }
  const {
    firstLine,
    fileContent
  } = t1;
  if (isUntracked) {
    let t2;
    if ($[7] !== filePath) {
      t2 = <Text bold={true}>{filePath}</Text>;
      $[7] = filePath;
      $[8] = t2;
    } else {
      t2 = $[8];
    }
    let t3;
    if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
      t3 = <Text dimColor={true}> (untracked)</Text>;
      $[9] = t3;
    } else {
      t3 = $[9];
    }
    let t4;
    if ($[10] !== t2) {
      t4 = <Box>{t2}{t3}</Box>;
      $[10] = t2;
      $[11] = t4;
    } else {
      t4 = $[11];
    }
    let t5;
    if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
      t5 = <Divider padding={4} />;
      $[12] = t5;
    } else {
      t5 = $[12];
    }
    let t6;
    if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
      t6 = <Text dimColor={true} italic={true}>New file not yet staged.</Text>;
      $[13] = t6;
    } else {
      t6 = $[13];
    }
    let t7;
    if ($[14] !== filePath) {
      t7 = <Box flexDirection="column">{t6}<Text dimColor={true} italic={true}>Run `git add {filePath}` to see line counts.</Text></Box>;
      $[14] = filePath;
      $[15] = t7;
    } else {
      t7 = $[15];
    }
    let t8;
    if ($[16] !== t4 || $[17] !== t7) {
      t8 = <Box flexDirection="column" width="100%">{t4}{t5}{t7}</Box>;
      $[16] = t4;
      $[17] = t7;
      $[18] = t8;
    } else {
      t8 = $[18];
    }
    return t8;
  }
  if (isBinary) {
    let t2;
    if ($[19] !== filePath) {
      t2 = <Box><Text bold={true}>{filePath}</Text></Box>;
      $[19] = filePath;
      $[20] = t2;
    } else {
      t2 = $[20];
    }
    let t3;
    if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
      t3 = <Divider padding={4} />;
      $[21] = t3;
    } else {
      t3 = $[21];
    }
    let t4;
    if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
      t4 = <Box flexDirection="column"><Text dimColor={true} italic={true}>Binary file - cannot display diff</Text></Box>;
      $[22] = t4;
    } else {
      t4 = $[22];
    }
    let t5;
    if ($[23] !== t2) {
      t5 = <Box flexDirection="column" width="100%">{t2}{t3}{t4}</Box>;
      $[23] = t2;
      $[24] = t5;
    } else {
      t5 = $[24];
    }
    return t5;
  }
  if (isLargeFile) {
    let t2;
    if ($[25] !== filePath) {
      t2 = <Box><Text bold={true}>{filePath}</Text></Box>;
      $[25] = filePath;
      $[26] = t2;
    } else {
      t2 = $[26];
    }
    let t3;
    if ($[27] === Symbol.for("react.memo_cache_sentinel")) {
      t3 = <Divider padding={4} />;
      $[27] = t3;
    } else {
      t3 = $[27];
    }
    let t4;
    if ($[28] === Symbol.for("react.memo_cache_sentinel")) {
      t4 = <Box flexDirection="column"><Text dimColor={true} italic={true}>Large file - diff exceeds 1 MB limit</Text></Box>;
      $[28] = t4;
    } else {
      t4 = $[28];
    }
    let t5;
    if ($[29] !== t2) {
      t5 = <Box flexDirection="column" width="100%">{t2}{t3}{t4}</Box>;
      $[29] = t2;
      $[30] = t5;
    } else {
      t5 = $[30];
    }
    return t5;
  }
  let t2;
  if ($[31] !== filePath) {
    t2 = <Text bold={true}>{filePath}</Text>;
    $[31] = filePath;
    $[32] = t2;
  } else {
    t2 = $[32];
  }
  let t3;
  if ($[33] !== isTruncated) {
    t3 = isTruncated && <Text dimColor={true}> (truncated)</Text>;
    $[33] = isTruncated;
    $[34] = t3;
  } else {
    t3 = $[34];
  }
  let t4;
  if ($[35] !== t2 || $[36] !== t3) {
    t4 = <Box>{t2}{t3}</Box>;
    $[35] = t2;
    $[36] = t3;
    $[37] = t4;
  } else {
    t4 = $[37];
  }
  let t5;
  if ($[38] === Symbol.for("react.memo_cache_sentinel")) {
    t5 = <Divider padding={4} />;
    $[38] = t5;
  } else {
    t5 = $[38];
  }
  let t6;
  if ($[39] !== columns || $[40] !== fileContent || $[41] !== filePath || $[42] !== firstLine || $[43] !== hunks) {
    t6 = hunks.length === 0 ? <Text dimColor={true}>No diff content</Text> : hunks.map((hunk, index) => <StructuredDiff key={index} patch={hunk} filePath={filePath} firstLine={firstLine} fileContent={fileContent} dim={false} width={columns - 2 - 2} />);
    $[39] = columns;
    $[40] = fileContent;
    $[41] = filePath;
    $[42] = firstLine;
    $[43] = hunks;
    $[44] = t6;
  } else {
    t6 = $[44];
  }
  let t7;
  if ($[45] !== t6) {
    t7 = <Box flexDirection="column">{t6}</Box>;
    $[45] = t6;
    $[46] = t7;
  } else {
    t7 = $[46];
  }
  let t8;
  if ($[47] !== isTruncated) {
    t8 = isTruncated && <Text dimColor={true} italic={true}>… diff truncated (exceeded 400 line limit)</Text>;
    $[47] = isTruncated;
    $[48] = t8;
  } else {
    t8 = $[48];
  }
  let t9;
  if ($[49] !== t4 || $[50] !== t7 || $[51] !== t8) {
    t9 = <Box flexDirection="column" width="100%">{t4}{t5}{t7}{t8}</Box>;
    $[49] = t4;
    $[50] = t7;
    $[51] = t8;
    $[52] = t9;
  } else {
    t9 = $[52];
  }
  return t9;
}