-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffLine.tsx
More file actions
93 lines (91 loc) · 2.56 KB
/
Copy pathDiffLine.tsx
File metadata and controls
93 lines (91 loc) · 2.56 KB
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
import { Text } from "ink";
import React from "react";
import type { DisplayLine } from "../utils/formatDiff.js";
function formatGutter(line: DisplayLine): string {
const before =
line.beforeLineNumber !== undefined ? String(line.beforeLineNumber).padStart(4) : " ";
const after =
line.afterLineNumber !== undefined ? String(line.afterLineNumber).padStart(4) : " ";
return `${before} ${after} │ `;
}
export function renderDiffLine(line: DisplayLine, isCursor = false): React.ReactNode {
const bold = isCursor;
switch (line.type) {
case "header":
return (
<Text bold color="yellow">
{line.text}
</Text>
);
case "separator":
return <Text dimColor>{line.text}</Text>;
case "add":
return (
<Text color="green" bold={bold}>
<Text dimColor>{formatGutter(line)}</Text>
{line.text}
</Text>
);
case "delete":
return (
<Text color="red" bold={bold}>
<Text dimColor>{formatGutter(line)}</Text>
{line.text}
</Text>
);
case "context":
return (
<Text bold={bold}>
<Text dimColor>{formatGutter(line)}</Text>
{line.text}
</Text>
);
case "truncate-context":
return <Text dimColor>{line.text}</Text>;
case "truncation":
return <Text dimColor>{line.text}</Text>;
case "comment-header":
return <Text bold>{line.text}</Text>;
case "comment":
return (
<Text>
{" "}
{line.text}
{line.reactionText ? <Text dimColor> {line.reactionText}</Text> : null}
</Text>
);
case "inline-comment":
return (
<Text color="magenta">
{" "}
{line.text}
{/* v8 ignore next -- inline comments rendered without reactions in tests */}
{line.reactionText ? <Text dimColor> {line.reactionText}</Text> : null}
</Text>
);
case "inline-reply":
return (
<Text color="magenta">
{" "}
{line.text}
{/* v8 ignore next -- inline replies rendered without reactions in tests */}
{line.reactionText ? <Text dimColor> {line.reactionText}</Text> : null}
</Text>
);
case "comment-reply":
return (
<Text>
{" "}
{line.text}
{line.reactionText ? <Text dimColor> {line.reactionText}</Text> : null}
</Text>
);
case "fold-indicator":
return (
<Text dimColor>
{" "}
{line.text}
</Text>
);
}
}