@kitlangton/ghui 0.1.18 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ import type { PullRequestItem } from "../domain.js"
2
+ import { colors } from "./colors.js"
3
+
4
+ type DiffStatsPart = { readonly key: string; readonly text: string; readonly color: string }
5
+
6
+ const diffStatsParts = (pullRequest: PullRequestItem): readonly DiffStatsPart[] => {
7
+ const files = pullRequest.changedFiles === 1 ? "1 file" : `${pullRequest.changedFiles} files`
8
+ return [
9
+ pullRequest.additions > 0 ? { key: "additions", text: `+${pullRequest.additions}`, color: colors.status.passing } : null,
10
+ pullRequest.deletions > 0 ? { key: "deletions", text: `-${pullRequest.deletions}`, color: colors.status.failing } : null,
11
+ { key: "files", text: files, color: colors.muted },
12
+ ].filter((part): part is DiffStatsPart => part !== null)
13
+ }
14
+
15
+ export const DiffStats = ({ pullRequest }: { pullRequest: PullRequestItem }) => {
16
+ if (!pullRequest.detailLoaded) return <span fg={colors.muted}>loading details</span>
17
+ const parts = diffStatsParts(pullRequest)
18
+ return (
19
+ <>
20
+ {parts.map((part, index) => (
21
+ <span key={part.key} fg={part.color}>{`${index > 0 ? " " : ""}${part.text}`}</span>
22
+ ))}
23
+ </>
24
+ )
25
+ }