Documentation
¶
Overview ¶
Package theme builds the application's visual styling by combining three orthogonal axes that the end user can choose independently:
- color theme — any of the bubbletint palettes (the color source),
- style preset — huh's built-in form structure (borders, prefixes, indicators); see StylePreset and BuildHuhStyles,
- mode — light or dark,
plus an optional accessibility pass that adjusts foreground colors for contrast and color-vision deficiencies (see accessibility.go).
Most consumers only need Active (the current palette), HuhThemeFunc (for huh forms), and the ColorAware interface. The package keeps a small amount of custom code: the semantic AppStyle/Styles mapping that lipgloss and huh do not provide, and the CVD accessibility engine that has no library equivalent. Everything structural is delegated to huh and lipgloss.
Index ¶
- Constants
- func BoxStyle() lipgloss.Style
- func BoxTitleStyle() lipgloss.Style
- func BuildHuhStyles(c *AppStyle, preset StylePreset, isDark bool) *huh.Styles
- func ColorHex(c color.Color) string
- func HuhThemeFunc() huh.ThemeFunc
- func NormalizeMode(mode string) string
- func ReapplyBg(s string, bg color.Color) string
- func RenderStatusBar(width int, left string, right string) string
- func RenderStatusBarStyled(width int, left string, right string, colorIndex int) string
- func ResolveTintIDForMode(requestedID string, mode string) string
- func SetCurrentTint(id string) error
- func SetThemePreferences(mode string, accessibility bool, style StylePreset)
- func SubtleStyle() lipgloss.Style
- type AppStyle
- type ColorAware
- type ColorPair
- type CommonKeyMap
- type StyleCombo
- type StylePreset
- type Styles
- type ThemePreferences
Constants ¶
const ( ThemeModeDark = "dark" ThemeModeLight = "light" )
const DefaultStylePreset = PresetCharm
DefaultStylePreset is used when no preset has been chosen or an unknown value is supplied. Charm has the most refined prefixes/indicators of the built-ins.
Variables ¶
This section is empty.
Functions ¶
func BoxTitleStyle ¶
BoxTitleStyle returns a bold title style using the current accent color.
func BuildHuhStyles ¶
func BuildHuhStyles(c *AppStyle, preset StylePreset, isDark bool) *huh.Styles
BuildHuhStyles produces huh form styles by combining three orthogonal axes:
- structure (borders, prefixes, indicators, padding, glyphs) from the chosen StylePreset's huh built-in theme,
- colors from the application palette c (derived from the active tint),
- the light/dark variant via isDark.
The preset theme is used as the structural starting point; overlayPaletteColors then re-tints every foreground/background/border so any of the 342 tints works with any preset. Because lipgloss styles are immutable values, re-applying a color preserves the preset's BorderStyle, padding, and SetString glyphs.
func ColorHex ¶ added in v0.1.7
ColorHex formats a color.Color as a "#rrggbb" string. A nil color yields "#000000". Shared by the router and inspector for OSC/diagnostic output.
func HuhThemeFunc ¶
HuhThemeFunc returns a ThemeFunc backed by the styles precomputed in the active palette (see fromTint), so there is no separate huh cache to maintain. It returns a shallow copy each call because huh forms mutate the styles they receive; huh.Styles holds only value-type fields, so a shallow copy is safe.
func NormalizeMode ¶
NormalizeMode returns the normalized theme mode value.
func ReapplyBg ¶ added in v0.1.7
ReapplyBg re-applies the background color after every ANSI reset in s. Child components emit `\x1b[m`/`\x1b[0m` resets mid-line; over SSH (where the OSC background is stripped) those resets expose the terminal default in unstyled gaps. Inserting the background SGR after each reset keeps the fill consistent. Shared by the router's main layout and the status bar.
func RenderStatusBar ¶
RenderStatusBar composes a left-aligned help string and a right-aligned status string into a single styled bar of the given width. If width <= 0 the function will return a simple un-padded rendering.
func RenderStatusBarStyled ¶
RenderStatusBarStyled renders the status bar. When colorIndex >= 0 it overrides the foreground with that ANSI index (0-255), which is useful for fade-in/out animations. Pass -1 to use the theme's StatusFg color.
func ResolveTintIDForMode ¶
ResolveTintIDForMode returns a tint ID matching the requested mode. If requestedID already matches, it is returned unchanged.
func SetCurrentTint ¶ added in v0.1.3
SetCurrentTint sets the active tint ID on the bubbletint global registry. It is safe to call from multiple goroutines.
func SetThemePreferences ¶
func SetThemePreferences(mode string, accessibility bool, style StylePreset)
SetThemePreferences updates global preferences used by Active and HuhThemeFunc.
func SubtleStyle ¶
SubtleStyle returns a dimmed text style for secondary / hint content.
Types ¶
type AppStyle ¶
type AppStyle struct {
// Fg is the primary foreground / body text color.
Fg color.Color
// Bg is the primary background color.
Bg color.Color
// Muted is used for secondary / dimmed text and inactive navigation items
// (maps to the "comment" or "bright_black" slot in most terminal themes).
Muted color.Color
// Border is used for borders and dividers (typically slightly darker than Muted).
Border color.Color
// Accent is the primary accent color: navigation titles, box titles, and
// tab / form highlights (maps to the purple/violet slot).
Accent color.Color
// SelectionBg is the background of the active / selected navigation item.
SelectionBg color.Color
// SelectionFg is the foreground of the selected navigation item.
SelectionFg color.Color
// StatusBg is the status bar background color.
StatusBg color.Color
// StatusFg is the status bar foreground color.
StatusFg color.Color
// Success is used for affirmative / selected-option states (green slot).
Success color.Color
// Error is used for error indicators (red slot).
Error color.Color
// Warning is used for warning / indicator cues (yellow slot).
Warning color.Color
Styles *Styles // pre-computed lipgloss styles (app chrome) for this palette
HuhStyles *huh.Styles // pre-computed huh form styles for this palette + current style preset
OrigTint *tint.Tint // the original tint this palette was derived from; used for debugging and testing
AccessibleTint *tint.Tint // a suggested tint with improved accessibility, if the original fails; used for debugging and testing
OrigPairs []ColorPair // all color combinations from the original tint
AccessiblePairs []ColorPair // the same pairs but with colors adjusted for accessibility where needed
}
AppStyle holds the semantic color palette for the application, derived from the active bubbletint theme. Each field maps a UI role to a color.Color. Call Active on every render to pick up live theme changes.
func Active ¶
func Active() *AppStyle
Active returns the current AppStyle palette derived from the active bubbletint. It is safe to call before the registry has been initialised; a built-in fallback palette (matching the Dracula aesthetic) is returned in that case.
type ColorAware ¶ added in v0.1.2
type ColorAware interface {
SetColors(c *AppStyle)
}
ColorAware is implemented by any component that accepts a shared color palette pointer.
type ColorPair ¶
ColorPair represents a foreground/background color combination with a name.
func AccessiblePairsFromTint ¶
AccessiblePairsFromTint returns accessibility-adjusted color pairs for a tint. Use this in diagnostics UIs; avoid in hot render paths.
type CommonKeyMap ¶
type CommonKeyMap struct {
Up key.Binding
Down key.Binding
Quit key.Binding
ToggleDetail key.Binding
}
CommonKeyMap provides a small set of common key bindings used across views.
func DefaultKeys ¶
func DefaultKeys() CommonKeyMap
type StyleCombo ¶
StyleCombo describes one concrete foreground/background pair used by the UI. It is primarily used for diagnostics and temporary accessibility tests.
func StyleCombosFromAppStyle ¶
func StyleCombosFromAppStyle(c *AppStyle) []StyleCombo
StyleCombosFromAppStyle returns concrete fg/bg combinations from named styles.
type StylePreset ¶ added in v0.1.2
type StylePreset string
StylePreset selects the structural source for huh form styling: borders, prefixes, indicators, padding, and glyphs. It is orthogonal to the color theme (supplied by the active bubbletint) and to the light/dark mode. Any preset can be combined with any of the registered tints.
const ( PresetBase StylePreset = "base" PresetCharm StylePreset = "charm" PresetDracula StylePreset = "dracula" PresetBase16 StylePreset = "base16" PresetCatppuccin StylePreset = "catppuccin" )
func NormalizePreset ¶ added in v0.1.2
func NormalizePreset(s string) StylePreset
NormalizePreset validates s and returns a known StylePreset, defaulting to DefaultStylePreset for empty or unrecognized values.
func StylePresets ¶ added in v0.1.2
func StylePresets() []StylePreset
StylePresets returns the selectable style presets in display order. Use this to build a settings picker.
func (StylePreset) DisplayName ¶ added in v0.1.2
func (p StylePreset) DisplayName() string
DisplayName returns a human-friendly label for the preset.
type Styles ¶
type Styles struct {
Name string
Help help.Styles
// Pre-computed styles — use these instead of calling lipgloss.NewStyle() inline.
Title lipgloss.Style
Subtitle lipgloss.Style
RealHeader lipgloss.Style
TextOnBg lipgloss.Style
Dim lipgloss.Style
BoarderActive lipgloss.Style
BoarderInactive lipgloss.Style
Item lipgloss.Style
SelectedItem lipgloss.Style
Send lipgloss.Style
FilterDim lipgloss.Style
StatusBase lipgloss.Style
StatusKey lipgloss.Style
StatusDesc lipgloss.Style
OverlayBorder lipgloss.Style
TabInactive lipgloss.Style
TabHover lipgloss.Style
SwatchDot lipgloss.Style
Row lipgloss.Style
Success lipgloss.Style // tint.Green
Error lipgloss.Style // tint.Red("Error")
Warning lipgloss.Style // tint.Yellow("Warning")
}
Styles holds pre-computed lipgloss styles derived from an AppStyle palette. Styles are rebuilt when the theme changes or the terminal background is detected.
func BuildStyles ¶
BuildStyles pre-computes commonly used lipgloss styles from one palette.
type ThemePreferences ¶
type ThemePreferences struct {
Mode string
Accessibility bool
Style StylePreset
}
ThemePreferences controls global theme behavior applied by Active and HuhThemeFunc. Mode selects light/dark, Style selects the huh structural preset, and Accessibility toggles the CVD foreground adjustments.
func ThemePreferencesSnapshot ¶
func ThemePreferencesSnapshot() ThemePreferences
ThemePreferencesSnapshot returns a copy of the current global preferences.