theme

package
v0.0.0-...-05a1a44 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

tui/theme/builder.go

tui/theme/palette.go

tui/theme/registry.go

tui/theme/theme.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDefault

func SetDefault(t Theme)

SetDefault replaces the global Theme. Typical usage: called once at program startup before any output is emitted. Goroutine-safe.

Types

type Option

type Option func(*builder)

Option configures a Theme built by From.

func WithColor

func WithColor(r Role, c lipgloss.AdaptiveColor) Option

WithColor overrides one palette slot.

func WithIcon

func WithIcon(k icon.IconKey, i icon.Icon) Option

WithIcon overrides one icon slot.

func WithName

func WithName(name string) Option

WithName sets the Theme's Name(). Useful when a tool ships multiple derived themes and wants them identifiable in logs.

type Palette

type Palette struct {
	// Semantic
	Info    lipgloss.AdaptiveColor
	Success lipgloss.AdaptiveColor
	Warning lipgloss.AdaptiveColor
	Error   lipgloss.AdaptiveColor
	Muted   lipgloss.AdaptiveColor
	Text    lipgloss.AdaptiveColor
	Heading lipgloss.AdaptiveColor
	Path    lipgloss.AdaptiveColor

	// Diff — functional colors for unified diff output; kept separate from
	// semantic roles so Success/Error can evolve independently.
	DiffAdd    lipgloss.AdaptiveColor // added lines (+)
	DiffRemove lipgloss.AdaptiveColor // removed lines (-)

	// Severity
	Critical lipgloss.AdaptiveColor
	High     lipgloss.AdaptiveColor
	Medium   lipgloss.AdaptiveColor
	Low      lipgloss.AdaptiveColor

	// Brand (SafeDep identity)
	BrandPrimary lipgloss.AdaptiveColor
	BrandAccent  lipgloss.AdaptiveColor

	// Background surfaces (for badges)
	BgCritical lipgloss.AdaptiveColor
	BgHigh     lipgloss.AdaptiveColor
	BgMedium   lipgloss.AdaptiveColor
	BgLow      lipgloss.AdaptiveColor
	BgInfo     lipgloss.AdaptiveColor
	BgSuccess  lipgloss.AdaptiveColor

	// BadgeText is the foreground color used inside saturated-background badges.
	// Kept as an explicit palette slot (rather than a hardcoded constant in the
	// style package) so high-contrast themes can override it.
	BadgeText lipgloss.AdaptiveColor
}

Palette is the exhaustive set of named colors used across tui components. It is intentionally CLOSED — no Custom map escape hatch. Runtime-keyed or product-specific palettes stay in the consuming tool.

func (Palette) ColorByRole

func (p Palette) ColorByRole(r Role) (lipgloss.AdaptiveColor, bool)

ColorByRole returns the AdaptiveColor for a role, or (zero, false).

func (Palette) WithColorByRole

func (p Palette) WithColorByRole(r Role, c lipgloss.AdaptiveColor) Palette

WithColorByRole returns a copy of p with the given role replaced.

type Role

type Role int

Role enumerates every named color slot. Used by theme.WithColor.

const (
	RoleInfo Role = iota
	RoleSuccess
	RoleWarning
	RoleError
	RoleMuted
	RoleText
	RoleHeading
	RolePath
	RoleDiffAdd
	RoleDiffRemove
	RoleCritical
	RoleHigh
	RoleMedium
	RoleLow
	RoleBrandPrimary
	RoleBrandAccent
	RoleBgCritical
	RoleBgHigh
	RoleBgMedium
	RoleBgLow
	RoleBgInfo
	RoleBgSuccess
	RoleBadgeText
)

type Theme

type Theme interface {
	Palette() Palette
	Icons() icon.Set
	Name() string
}

Theme is the unit of design language injection. Every component reads the installed Theme at render time via Default(); no component caches the resolved theme across renders.

func Default

func Default() Theme

Default returns the globally installed Theme. Safe to call from any goroutine; components call this at every render.

func From

func From(base Theme, opts ...Option) Theme

From builds a new Theme by copying base and applying options. base is not mutated. Use this to tweak a handful of colors or icons without writing a full Theme implementation.

func SafeDep

func SafeDep() Theme

SafeDep returns the canonical SafeDep Theme.

The returned value is a fresh copy on each call; callers may mutate it freely without affecting the global default.

Jump to

Keyboard shortcuts

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