Repository navigation
Expand file tree
/
Copy paththeme.go
More file actions
230 lines (218 loc) · 7.49 KB
/
Copy paththeme.go
File metadata and controls
230 lines (218 loc) · 7.49 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
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
package main
import (
"image/color"
"charm.land/lipgloss/v2"
"github.com/alecthomas/chroma/v2"
chromastyles "github.com/alecthomas/chroma/v2/styles"
)
// ThemeName is the chroma style the palette and syntax highlighting are
// derived from. Overridable via the --theme flag.
var ThemeName = "catppuccin-mocha"
// knownThemes lists the themes selectable via --theme. All are chroma
// styles shipped with the chroma library, so the palette and syntax
// highlighting stay in sync automatically.
var knownThemes = map[string]bool{
"catppuccin-mocha": true,
"catppuccin-macchiato": true,
"catppuccin-frappe": true,
"catppuccin-latte": true,
"dracula": true,
"gruvbox": true,
"monokai": true,
"nord": true,
"solarized-dark": true,
"solarized-light": true,
"tokyonight-night": true,
"tokyonight-storm": true,
"onedark": true,
"doom-one": true,
}
// palette is the single source of truth for colors. It is derived from
// the chroma catppuccin-mocha style so the TUI matches that theme.
type palette struct {
bg color.Color // base
surface color.Color // surface0/1
border color.Color // surface2
borderHi color.Color // overlay0
primary color.Color // blue (was keyword mauve accents)
accent color.Color // mauve
text color.Color // text
muted color.Color // overlay1 (comments)
add color.Color // green
addBg color.Color // green on surface
del color.Color // red
delBg color.Color // red on surface
warn color.Color // peach
}
// chromaColor resolves a token's foreground color from the style,
// falling back to the provided default when unset.
func chromaColor(st *chroma.Style, tok chroma.TokenType, def string) color.Color {
if e := st.Get(tok); e.Colour.IsSet() {
return lipgloss.Color(e.Colour.String())
}
return lipgloss.Color(def)
}
func chromaBg(st *chroma.Style, def string) color.Color {
if e := st.Get(chroma.Background); e.Background.IsSet() {
return lipgloss.Color(e.Background.String())
}
return lipgloss.Color(def)
}
// contrastSurface picks a card/overlay surface that stays readable against bg.
// Dark themes use a lifted surface0; light themes shade the panel slightly.
func contrastSurface(bg color.Color) color.Color {
r16, g16, b16, _ := bg.RGBA()
rf, gf, bf := float64(r16)/65535.0, float64(g16)/65535.0, float64(b16)/65535.0
lum := 0.2126*rf + 0.7152*gf + 0.0722*bf
if lum > 0.55 {
// Light background: fixed soft panel that stays darker than paper white.
return lipgloss.Color("#ccd0da")
}
// Dark background: Catppuccin-like surface0 (works across mocha/dracula/nord).
return lipgloss.Color("#313244")
}
func newPalette() palette {
st := chromastyles.Get(ThemeName)
// Derived from the chroma catppuccin-mocha style tokens; the
// fallbacks are the canonical Catppuccin Mocha hex values.
bg := chromaBg(st, "#1e1e2e") // base
return palette{
bg: bg,
surface: contrastSurface(bg),
border: lipgloss.Color("#45475a"), // surface1
borderHi: lipgloss.Color("#585b70"), // surface2
primary: chromaColor(st, chroma.NameFunction, "#89b4fa"), // blue
accent: chromaColor(st, chroma.Keyword, "#cba6f7"), // mauve
text: chromaColor(st, chroma.Text, "#cdd6f4"), // text
muted: chromaColor(st, chroma.Comment, "#6c7086"), // overlay1
add: chromaColor(st, chroma.GenericInserted, "#a6e3a1"), // green
addBg: lipgloss.Color("#24312b"), // green-tinted surface
del: chromaColor(st, chroma.GenericDeleted, "#f38ba8"), // red
delBg: lipgloss.Color("#322430"), // red-tinted surface
warn: chromaColor(st, chroma.LiteralNumber, "#fab387"), // peach
}
}
// styles holds every lipgloss style used by the app, built once from p.
type styles struct {
p palette
header lipgloss.Style
headerBrand lipgloss.Style
headerPath lipgloss.Style
stats lipgloss.Style
paneTitle lipgloss.Style // unfocused pane title (muted label)
paneTitleOn lipgloss.Style // focused pane title (primary label)
rule lipgloss.Style // separator under unfocused pane title
ruleActive lipgloss.Style // separator under focused pane title
fileRow lipgloss.Style
fileRowSel lipgloss.Style
fileRowNew lipgloss.Style
fileRowDel lipgloss.Style
fileRowBin lipgloss.Style
gutter lipgloss.Style
addLine lipgloss.Style
addWord lipgloss.Style
delLine lipgloss.Style
delWord lipgloss.Style
ctxLine lipgloss.Style
diffHeader lipgloss.Style
divider lipgloss.Style
footer lipgloss.Style
footerKey lipgloss.Style
footerDesc lipgloss.Style
empty lipgloss.Style
helpOverlay lipgloss.Style
helpKey lipgloss.Style
filterPrompt lipgloss.Style
badgeNew lipgloss.Style
badgeDel lipgloss.Style
badgeBin lipgloss.Style
}
func newStyles(p palette) styles {
base := lipgloss.NewStyle().Background(p.bg)
return styles{
p: p,
// The status bar's top rule is drawn manually in renderStatusBar so it
// can carry a ┴ junction where the vertical divider meets it.
header: lipgloss.NewStyle().
Foreground(p.muted).
Padding(0, 1),
headerBrand: lipgloss.NewStyle().
Foreground(p.primary).
Bold(true),
headerPath: lipgloss.NewStyle().
Foreground(p.muted),
stats: base.
Foreground(p.muted).
Padding(0, 1),
// Pane titles: plain label row. The focused pane's label is bold
// primary; the unfocused pane's is muted. A separator rule is drawn
// beneath the titles by the view (see rule / ruleActive).
paneTitle: lipgloss.NewStyle().
Foreground(p.muted).
Padding(0, 1),
paneTitleOn: lipgloss.NewStyle().
Foreground(p.primary).
Bold(true).
Padding(0, 1),
rule: lipgloss.NewStyle().
Foreground(p.border),
ruleActive: lipgloss.NewStyle().
Foreground(p.primary),
fileRow: base.
Foreground(p.text).
Padding(0, 1),
fileRowSel: lipgloss.NewStyle().
Background(p.surface).
Foreground(p.primary).
Bold(true).
Padding(0, 1),
fileRowNew: base.Foreground(p.add).Padding(0, 1),
fileRowDel: base.Foreground(p.del).Padding(0, 1),
fileRowBin: base.Foreground(p.accent).Padding(0, 1),
gutter: base.Foreground(p.muted),
addLine: lipgloss.NewStyle().
Foreground(p.add).
Background(p.addBg),
addWord: lipgloss.NewStyle().
Foreground(p.bg).
Background(p.add).
Bold(true),
delLine: lipgloss.NewStyle().
Foreground(p.del).
Background(p.delBg),
delWord: lipgloss.NewStyle().
Foreground(p.bg).
Background(p.del).
Bold(true),
ctxLine: base.Foreground(p.text),
diffHeader: base.Foreground(p.accent).Bold(true),
divider: base.Foreground(p.border),
footer: base.
Foreground(p.muted).
Padding(0, 1),
footerKey: lipgloss.NewStyle().
Foreground(p.primary).
Bold(true),
footerDesc: lipgloss.NewStyle().
Foreground(p.muted),
empty: base.
Foreground(p.muted).
Italic(true),
helpOverlay: lipgloss.NewStyle().
Foreground(p.text).
Background(p.surface).
Border(lipgloss.RoundedBorder()).
BorderForeground(p.primary).
BorderBackground(p.surface).
Padding(1, 2),
helpKey: lipgloss.NewStyle().
Foreground(p.primary).
Bold(true),
filterPrompt: lipgloss.NewStyle().
Foreground(p.primary).
Bold(true),
badgeNew: lipgloss.NewStyle().Foreground(p.add).Bold(true),
badgeDel: lipgloss.NewStyle().Foreground(p.del).Bold(true),
badgeBin: lipgloss.NewStyle().Foreground(p.accent).Bold(true),
}
}