Every colour was a 256-colour ANSI index hardcoded in styles.go, so changing the palette meant editing the styles themselves. This puts a semantic token set between the two: styles name roles, a theme supplies the colours. internal/theme holds the twelve tokens, the two built-ins (gruvbox-dark, the new default, and gruvbox-light) and the loader for user themes in ~/.config/terdut-tui/themes/. A user file may 'extends:' a built-in and override only what it cares about, and may shadow a built-in name to tweak it in place. Unknown keys, malformed colours and incomplete themes are refused with a message naming what went wrong. Colours are truecolor hex now: lipgloss downsamples for 256- and 16-colour terminals and honours NO_COLOR, so themes carry no fallbacks of their own. An ANSI index is still accepted for anyone who would rather follow their terminal's own palette. The 21 package-level style vars become a Styles struct on the Model, which is what rule 3 asked for all along; the four free functions in view.go take one as their first argument. The embedded bubbles components are restyled from the same tokens — otherwise a theme would leave a pink selected row and grey help text behind. Note that the table's Cell style deliberately keeps no foreground: bubbles renders cells before wrapping the row in Selected, so a colour there cuts the selection highlight short.
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package theme
|
||||
|
||||
import "sort"
|
||||
|
||||
// The gruvbox palettes, in the author's original names. Dark uses the bright
|
||||
// variants and light the faded ones, which is what keeps each readable against
|
||||
// its own background.
|
||||
const (
|
||||
darkBg0 = "#282828"
|
||||
darkFg1 = "#ebdbb2"
|
||||
darkGray = "#928374"
|
||||
darkRed = "#fb4934"
|
||||
darkGrn = "#b8bb26"
|
||||
darkYel = "#fabd2f"
|
||||
darkBlu = "#83a598"
|
||||
darkAqua = "#8ec07c"
|
||||
darkOrng = "#fe8019"
|
||||
|
||||
lightBg0 = "#fbf1c7"
|
||||
lightFg1 = "#3c3836"
|
||||
lightFg4 = "#7c6f64"
|
||||
lightRed = "#9d0006"
|
||||
lightGrn = "#79740e"
|
||||
lightYel = "#b57614"
|
||||
lightBlu = "#076678"
|
||||
lightAqua = "#427b58"
|
||||
lightOrng = "#af3a03"
|
||||
)
|
||||
|
||||
// GruvboxDark is the default scheme. It assumes a dark terminal background:
|
||||
// themes colour foregrounds only, so the terminal supplies the canvas.
|
||||
var GruvboxDark = Theme{
|
||||
Name: "gruvbox-dark",
|
||||
|
||||
Primary: darkBlu,
|
||||
OnPrimary: darkBg0,
|
||||
Text: darkFg1,
|
||||
Muted: darkGray,
|
||||
Accent: darkOrng,
|
||||
|
||||
Firing: darkRed,
|
||||
Resolved: darkGrn,
|
||||
Error: darkRed,
|
||||
|
||||
SevCritical: darkRed,
|
||||
SevError: darkOrng,
|
||||
SevWarning: darkYel,
|
||||
SevInfo: darkAqua,
|
||||
}
|
||||
|
||||
// GruvboxLight is the same scheme against a light terminal background.
|
||||
var GruvboxLight = Theme{
|
||||
Name: "gruvbox-light",
|
||||
|
||||
Primary: lightBlu,
|
||||
OnPrimary: lightBg0,
|
||||
Text: lightFg1,
|
||||
Muted: lightFg4,
|
||||
Accent: lightOrng,
|
||||
|
||||
Firing: lightRed,
|
||||
Resolved: lightGrn,
|
||||
Error: lightRed,
|
||||
|
||||
SevCritical: lightRed,
|
||||
SevError: lightOrng,
|
||||
SevWarning: lightYel,
|
||||
SevInfo: lightAqua,
|
||||
}
|
||||
|
||||
// Default is the theme used when the config names none.
|
||||
var Default = GruvboxDark
|
||||
|
||||
var builtins = map[string]Theme{
|
||||
GruvboxDark.Name: GruvboxDark,
|
||||
GruvboxLight.Name: GruvboxLight,
|
||||
}
|
||||
|
||||
// BuiltinNames lists the compiled-in themes, sorted, for error messages and
|
||||
// documentation.
|
||||
func BuiltinNames() []string {
|
||||
names := make([]string, 0, len(builtins))
|
||||
for name := range builtins {
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
return names
|
||||
}
|
||||
Reference in New Issue
Block a user