Documentation
¶
Overview ¶
Package themes ports the desktop app's color schemes to the terminal: the registry of built-in themes, the --z-* tokens each one defines, and the custom themes users drop under <config>/themes. It knows nothing about how the terminal UI paints; it only resolves a selection to a palette.
Index ¶
- Constants
- Variables
- func Contrast(a, b RGB) float64
- func CustomSlug(id string) (string, bool)
- func Families() []string
- func FlattenBuiltin(desktopCSS, source string) (string, error)
- func IsFamily(name string) bool
- func Luminance(c RGB) float64
- func NormalizeMode(mode string) string
- func ResolveAuto(family string, dark bool, currentID string) string
- type Custom
- type Option
- type Palette
- type RGB
- type Selection
- type Tokens
Constants ¶
const CustomPrefix = "custom-"
CustomPrefix turns a custom theme's folder name into its theme id.
const DefaultID = "dark-hard"
DefaultID is the theme a fresh install starts on, as on the desktop.
const FamilyCustom = "custom"
FamilyCustom is the family of the themes users author themselves.
Variables ¶
var Builtin = []Option{ {ID: "apple-light", Label: "Apple · Light", Family: "apple"}, {ID: "apple-dark", Label: "Apple · Dark", Family: "apple", Dark: true}, {ID: "light-hard", Label: "Gruvbox · Light Hard", Family: "gruvbox", Variant: "hard"}, {ID: "light-medium", Label: "Gruvbox · Light Medium", Family: "gruvbox", Variant: "medium"}, {ID: "light-soft", Label: "Gruvbox · Light Soft", Family: "gruvbox", Variant: "soft"}, {ID: "dark-hard", Label: "Gruvbox · Dark Hard", Family: "gruvbox", Dark: true, Variant: "hard"}, {ID: "dark-medium", Label: "Gruvbox · Dark Medium", Family: "gruvbox", Dark: true, Variant: "medium"}, {ID: "dark-soft", Label: "Gruvbox · Dark Soft", Family: "gruvbox", Dark: true, Variant: "soft"}, {ID: "catppuccin-latte", Label: "Catppuccin · Latte", Family: "catppuccin", Variant: "latte"}, {ID: "catppuccin-frappe", Label: "Catppuccin · Frappé", Family: "catppuccin", Dark: true, Variant: "frappe"}, {ID: "catppuccin-macchiato", Label: "Catppuccin · Macchiato", Family: "catppuccin", Dark: true, Variant: "macchiato"}, {ID: "catppuccin-mocha", Label: "Catppuccin · Mocha", Family: "catppuccin", Dark: true, Variant: "mocha"}, {ID: "github-light", Label: "GitHub · Light", Family: "github", Variant: "default"}, {ID: "github-light-high-contrast", Label: "GitHub · Light High Contrast", Family: "github", Variant: "high-contrast"}, {ID: "github-dark", Label: "GitHub · Dark", Family: "github", Dark: true, Variant: "default"}, {ID: "github-dark-dimmed", Label: "GitHub · Dark Dimmed", Family: "github", Dark: true, Variant: "dimmed"}, {ID: "github-dark-high-contrast", Label: "GitHub · Dark High Contrast", Family: "github", Dark: true, Variant: "high-contrast"}, {ID: "solarized-light", Label: "Solarized · Light", Family: "solarized"}, {ID: "solarized-dark", Label: "Solarized · Dark", Family: "solarized", Dark: true}, {ID: "one-light", Label: "One · Light", Family: "one"}, {ID: "one-dark", Label: "One · Dark", Family: "one", Dark: true}, {ID: "nord-light", Label: "Nord · Light", Family: "nord"}, {ID: "nord-dark", Label: "Nord · Dark", Family: "nord", Dark: true}, {ID: "tokyo-night-day", Label: "Tokyo Night · Day", Family: "tokyo-night"}, {ID: "tokyo-night-storm", Label: "Tokyo Night · Storm", Family: "tokyo-night", Dark: true}, {ID: "kanagawa-wave", Label: "Kanagawa · Wave", Family: "kanagawa", Dark: true, Variant: "wave"}, {ID: "kanagawa-dragon", Label: "Kanagawa · Dragon", Family: "kanagawa", Dark: true, Variant: "dragon"}, {ID: "kanagawa-paper-ink", Label: "Kanagawa · Paper Ink", Family: "kanagawa", Dark: true, Variant: "paper-ink"}, {ID: "kanagawa-lotus", Label: "Kanagawa · Lotus", Family: "kanagawa", Variant: "lotus"}, {ID: "black-metal", Label: "Black Metal · Black", Family: "black-metal", Dark: true}, {ID: "black-metal-day", Label: "Black Metal · Day", Family: "black-metal"}, {ID: "rose-pine-main", Label: "Rosé Pine · Main", Family: "rose-pine", Dark: true, Variant: "main"}, {ID: "rose-pine-moon", Label: "Rosé Pine · Moon", Family: "rose-pine", Dark: true, Variant: "moon"}, {ID: "rose-pine-dawn", Label: "Rosé Pine · Dawn", Family: "rose-pine", Variant: "dawn"}, }
Builtin mirrors THEMES in the desktop's lib/themes.ts, in its order.
var TokenNames = []string{
"bg", "bg-softer", "bg-1", "bg-2", "bg-3", "bg-4",
"fg", "fg-1", "fg-2",
"grey-2", "grey-1", "grey-0", "grey-dim",
"accent", "accent-soft", "accent-muted",
"red", "green", "yellow", "blue", "purple", "aqua",
}
TokenNames lists the color tokens in the order the desktop writes them.
Functions ¶
func CustomSlug ¶
CustomSlug extracts the folder name from a `custom-<slug>` id.
func FlattenBuiltin ¶
FlattenBuiltin turns the desktop's stylesheet into the builtin.css this package embeds: one block per registry theme, every color token spelled out. On the desktop the tokens cascade (the bare :root holds Gruvbox Light, the three Gruvbox darks share a block, each variant overrides a few); flattening keeps that cascade out of the terminal. It fails when a registry theme is missing a token, so a desktop change cannot slip in half-applied. The gen command is its only caller.
func NormalizeMode ¶
NormalizeMode maps a theme_mode onto light, dark or auto. The terminal has long called auto "system", so both names mean the same.
Types ¶
type Custom ¶
type Custom struct {
Slug string
Name string
// Modes is light, dark or both. A single-mode theme pins its mode.
Modes string
// contains filtered or unexported fields
}
Custom is a theme a user authored: a folder under <config>/themes holding a theme.css and, optionally, a manifest.json. The desktop app owns the format; the terminal reads the same folder.
func ListCustom ¶
ListCustom returns every loadable theme folder, by name.
func LoadCustom ¶
LoadCustom reads one custom theme. The only hard requirement is a readable theme.css; a missing or broken manifest names the theme after its folder and assumes both modes.
type Palette ¶
Palette is a theme resolved to one mode.
func BuiltinPalette ¶
BuiltinPalette is the palette of a built-in theme.
func Resolve ¶
Resolve turns a selection into the palette to draw with. systemDark answers "auto"; customDir is where custom themes live. A selection that cannot be honored (a custom theme that is gone) still returns a usable palette, together with the reason.
func (*Palette) ApplyTweaks ¶
ApplyTweaks overlays the desktop's Quick tweaks ([tweaks] in config.toml): the accent and the six syntax hues, keyed by slug.
type RGB ¶
type RGB struct{ R, G, B uint8 }
RGB is one opaque color.
func EnsureContrast ¶
EnsureContrast nudges fg toward anchor until it reads against bg at the wanted ratio. Palettes tuned for a backlit app window keep their hue; only the colors a terminal would render too faint move, and only as far as needed.
func ParseColor ¶
ParseColor reads `#rgb`, `#rrggbb`, `rgb(r, g, b)` or the bare `r g b` triplet the desktop's tokens are written in.