Repository navigation
Expand file tree
/
Copy paththeme.go
More file actions
133 lines (116 loc) · 3.43 KB
/
Copy paththeme.go
File metadata and controls
133 lines (116 loc) · 3.43 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
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
package tui
import (
"fmt"
"strings"
"github.com/Aneeshie/zerrcode/internal/diff"
"github.com/Aneeshie/zerrcode/internal/permissions"
"github.com/charmbracelet/x/ansi"
)
// ANSI colors for a minimal, distraction-free terminal theme.
const (
reset = "\x1b[0m"
bold = "\x1b[1m"
dim = "\x1b[2m"
ital = "\x1b[3m"
)
var (
// Brand & Accents
colBrand = "\x1b[38;2;167;139;250m" // #a78bfa (Soft Violet)
colUser = "\x1b[38;2;56;189;248m" // #38bdf8 (Sky Cyan)
colTool = "\x1b[38;2;251;191;36m" // #fbbf24 (Warm Amber)
colGreen = "\x1b[38;2;52;211;153m" // #34d399 (Emerald)
colRed = "\x1b[38;2;248;113;113m" // #f87171 (Soft Red)
// Neutrals
colBorder = "\x1b[38;2;51;65;85m" // #334155 (Dark Slate)
colMuted = "\x1b[38;2;100;116;139m" // #64748b (Slate Muted)
colText = "\x1b[38;2;226;232;240m" // #e2e8f0 (Light Text)
)
func fg(col, text string) string {
return col + text + reset
}
func divider(width int) string {
if width <= 0 {
return ""
}
return colBorder + strings.Repeat("─", width) + reset
}
func formatChangeSummary(c permissions.FileChange) string {
switch c.Op {
case permissions.OpCreate:
return fmt.Sprintf("created %s (+%d lines)", c.Path, c.Diff.Added)
case permissions.OpDelete:
return fmt.Sprintf("deleted %s (-%d lines)", c.Path, c.Diff.Removed)
case permissions.OpRename:
return fmt.Sprintf("renamed %s -> %s (+%d -%d)", c.OldPath, c.Path, c.Diff.Added, c.Diff.Removed)
default:
return fmt.Sprintf("modified %s (+%d -%d)", c.Path, c.Diff.Added, c.Diff.Removed)
}
}
func renderDiffLines(fd diff.FileDiff, maxWidth int, indent string) []string {
if fd.Binary {
return []string{indent + dim + fg(colTool, "[Binary file differences]")}
}
if fd.Empty() {
return []string{indent + dim + fg(colMuted, "(no content changes)")}
}
var lines []string
for _, l := range fd.Lines {
truncated := l.Text
if maxWidth > 0 && ansi.StringWidth(indent)+2+ansi.StringWidth(truncated) > maxWidth {
truncated = ansi.Truncate(truncated, maxWidth-ansi.StringWidth(indent)-5, "...")
}
switch l.Kind {
case diff.Add:
lines = append(lines, indent+fg(colGreen, "+ "+truncated))
case diff.Del:
lines = append(lines, indent+fg(colRed, "- "+truncated))
case diff.Hunk:
lines = append(lines, indent+dim+fg(colUser, truncated))
case diff.Meta:
lines = append(lines, indent+dim+fg(colMuted, truncated))
default:
lines = append(lines, indent+dim+fg(colMuted, " "+truncated))
}
}
return lines
}
// wrapLines wraps a text block cleanly within a given maxWidth, preserving paragraphs.
func wrapLines(content string, maxWidth int, indent string) []string {
if maxWidth <= 0 {
maxWidth = 60
}
effectiveWidth := maxWidth - ansi.StringWidth(indent)
if effectiveWidth < 10 {
effectiveWidth = 10
}
var result []string
rawLines := strings.Split(content, "\n")
for _, rawLine := range rawLines {
if rawLine == "" {
result = append(result, "")
continue
}
words := strings.Fields(rawLine)
if len(words) == 0 {
result = append(result, "")
continue
}
var line strings.Builder
for _, w := range words {
wLen := ansi.StringWidth(w)
if line.Len() == 0 {
line.WriteString(w)
} else if ansi.StringWidth(line.String())+1+wLen <= effectiveWidth {
line.WriteString(" " + w)
} else {
result = append(result, indent+line.String())
line.Reset()
line.WriteString(w)
}
}
if line.Len() > 0 {
result = append(result, indent+line.String())
}
}
return result
}