theme

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 12 Imported by: 0

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

View Source
const (
	ThemeModeDark  = "dark"
	ThemeModeLight = "light"
)
View Source
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 BoxStyle

func BoxStyle() lipgloss.Style

BoxStyle returns a rounded-border box style using the current theme colors.

func BoxTitleStyle

func BoxTitleStyle() lipgloss.Style

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

func ColorHex(c color.Color) string

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

func HuhThemeFunc() huh.ThemeFunc

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

func NormalizeMode(mode string) string

NormalizeMode returns the normalized theme mode value.

func ReapplyBg added in v0.1.7

func ReapplyBg(s string, bg color.Color) string

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

func RenderStatusBar(width int, left string, right string) string

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

func RenderStatusBarStyled(width int, left string, right string, colorIndex int) string

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

func ResolveTintIDForMode(requestedID string, mode string) string

ResolveTintIDForMode returns a tint ID matching the requested mode. If requestedID already matches, it is returned unchanged.

func SetCurrentTint added in v0.1.3

func SetCurrentTint(id string) error

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

func SubtleStyle() lipgloss.Style

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.

func FromTint

func FromTint(t *tint.Tint) *AppStyle

FromTint maps a *tint.Tint onto the application's semantic AppStyle. Every field has a hardcoded fallback that works in any 256-color terminal.

func FromTintWithOptions

func FromTintWithOptions(t *tint.Tint, accessibility bool) *AppStyle

FromTintWithOptions maps a tint into AppStyle with optional accessibility adjustments for semantic foreground/background pairs.

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

type ColorPair struct {
	Name string
	Fg   color.Color
	Bg   color.Color
}

ColorPair represents a foreground/background color combination with a name.

func AccessiblePairsFromTint

func AccessiblePairsFromTint(t *tint.Tint) []ColorPair

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

type StyleCombo struct {
	Name string
	Fg   color.Color
	Bg   color.Color
}

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

	NavTitle     lipgloss.Style
	NavActive    lipgloss.Style
	NavInactive  lipgloss.Style
	NavContainer 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

func BuildStyles(c *AppStyle) *Styles

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL