Documentation
¶
Overview ¶
Package charmtheme provides a unified theming system for Charmbracelet libraries (huh, Lipgloss, Glamour). Define your theme once and reuse it across adapters while automatically adapting to light/dark terminals.
Package charmtheme provides a unified, adaptive theming system for Charmbracelet TUIs.
Index ¶
- func AdaptiveColor(light, dark string) lipgloss.AdaptiveColor
- func AdjustBrightness(r, g, b uint8, factor float64) (uint8, uint8, uint8)
- func AdjustSaturation(r, g, b uint8, factor float64) (uint8, uint8, uint8)
- func AutoAdaptiveColor(lightHex string) lipgloss.AdaptiveColor
- func DegradeColorForProfile(color lipgloss.AdaptiveColor, profile termenv.Profile, isDark bool) string
- func ParseHex(hex string) (uint8, uint8, uint8, error)
- func ShouldUseColor() bool
- func ToHex(r, g, b uint8) string
- type BrandColors
- type Role
- type TerminalCapabilities
- type Theme
- func (t Theme) GlamourOption() glamour.TermRendererOption
- func (t Theme) GlamourStyleJSON() (string, error)
- func (t Theme) Huh() *huh.Theme
- func (t Theme) Lipgloss(role Role) lipgloss.Style
- func (t Theme) RenderError(text string) string
- func (t Theme) RenderHeading(text string) string
- func (t Theme) RenderInfo(text string) string
- func (t Theme) RenderSuccess(text string) string
- func (t Theme) RenderWarning(text string) string
- func (t Theme) ResolveColor(role Role) lipgloss.AdaptiveColor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdaptiveColor ¶
func AdaptiveColor(light, dark string) lipgloss.AdaptiveColor
AdaptiveColor constructs a lipgloss.AdaptiveColor from the given light/dark hex strings. Light should be tuned for light backgrounds, dark for dark backgrounds.
func AdjustBrightness ¶
AdjustBrightness applies a multiplier to the HSL lightness component of the supplied RGB color. Values >1 increase brightness, <1 decrease brightness.
func AdjustSaturation ¶
AdjustSaturation scales the HSL saturation component by the provided factor. Values >1 intensify the color, <1 desaturate it.
func AutoAdaptiveColor ¶
func AutoAdaptiveColor(lightHex string) lipgloss.AdaptiveColor
AutoAdaptiveColor derives a dark-variant color from the provided light variant. The light hex is used as provided, while the dark variant goes through a brightness/saturation adjustment to keep contrast on dark terminals. If parsing the light color fails, the returned color uses the same value for both variants.
func DegradeColorForProfile ¶
func DegradeColorForProfile(color lipgloss.AdaptiveColor, profile termenv.Profile, isDark bool) string
DegradeColorForProfile converts an adaptive color into a format suitable for the provided terminal profile. Colors automatically degrade for limited palettes while respecting adaptive light/dark variants.
func ParseHex ¶
ParseHex parses strings in the form "#RRGGBB" or "RRGGBB" into RGB components. It returns errInvalidHex for malformed inputs.
func ShouldUseColor ¶
func ShouldUseColor() bool
ShouldUseColor returns whether the library should emit ANSI colors based on conventional environment variables.
Types ¶
type BrandColors ¶ added in v0.2.0
BrandColors represents a minimal brand palette used to derive a Theme. Empty fields are treated as "keep defaults" so callers can override only the colors they care about.
type Role ¶
type Role string
Role represents a semantic UI element that needs consistent theming across libraries.
const ( RoleHeading Role = "heading" RoleSubheading Role = "subheading" RoleBody Role = "body" RoleCode Role = "code" RoleEmphasis Role = "emphasis" RoleStrong Role = "strong" RoleError Role = "error" RoleSuccess Role = "success" RoleWarning Role = "warning" RoleInfo Role = "info" RoleFieldLabel Role = "field_label" RoleFieldValue Role = "field_value" RoleFieldDescription Role = "field_description" RoleButton Role = "button" RoleButtonActive Role = "button_active" RoleBorder Role = "border" RoleSelection Role = "selection" RoleCommandName Role = "command_name" RoleCommandShort Role = "command_short" RoleFlagName Role = "flag_name" RoleFlagShort Role = "flag_short" RoleTableHeader Role = "table_header" RoleTableCell Role = "table_cell" )
type TerminalCapabilities ¶
type TerminalCapabilities struct {
ColorProfile termenv.Profile
IsTTY bool
Width int
Height int
HasDarkBg bool
}
TerminalCapabilities describes what the current terminal supports.
func DetectTerminalCapabilities ¶
func DetectTerminalCapabilities() TerminalCapabilities
DetectTerminalCapabilities inspects stdout to determine terminal support.
type Theme ¶
type Theme struct {
// Core palette - adaptive for light/dark terminals
Primary lipgloss.AdaptiveColor
Secondary lipgloss.AdaptiveColor
Accent lipgloss.AdaptiveColor
// Semantic colors
Success lipgloss.AdaptiveColor
Error lipgloss.AdaptiveColor
Warning lipgloss.AdaptiveColor
Info lipgloss.AdaptiveColor
// Surface colors
Background lipgloss.AdaptiveColor
Surface lipgloss.AdaptiveColor
Muted lipgloss.AdaptiveColor
// Text roles
TextNormal lipgloss.AdaptiveColor
TextMuted lipgloss.AdaptiveColor
TextStrong lipgloss.AdaptiveColor
// Typography preferences
HeaderPrefix string
BoldHeadings bool
BoldCommands bool
ItalicEmphasis bool
// Table styling
UseTableBorders bool
UseColumnDividers bool
UseHeaderDivider bool
// Code highlighting
ChromaStyle string
// Layout
BorderRadius int
Padding int
Compact bool
AlignDescriptions bool
}
Theme defines a unified color scheme and typography across Charm TUI libraries.
func DefaultTheme ¶
func DefaultTheme() Theme
DefaultTheme returns an opinionated theme tuned for modern terminals.
func DraculaTheme ¶ added in v0.2.0
func DraculaTheme() Theme
DraculaTheme returns a Theme based on the popular Dracula palette.
func FromBrandColors ¶ added in v0.2.0
func FromBrandColors(b BrandColors) Theme
FromBrandColors generates a Theme from up to three brand colors. It starts from DefaultTheme to inherit typography, layout, and semantic defaults, then selectively overrides the core palette. Invalid hex inputs are ignored.
func GruvboxTheme ¶ added in v0.2.0
func GruvboxTheme() Theme
GruvboxTheme returns a Theme modeled after Gruvbox (medium contrast).
func MinimalTheme ¶
func MinimalTheme() Theme
MinimalTheme is a conservative style designed for basic or low-color terminals.
func NordTheme ¶ added in v0.2.0
func NordTheme() Theme
NordTheme returns a Theme based on the Nord color palette.
func SolarizedDarkTheme ¶ added in v0.2.0
func SolarizedDarkTheme() Theme
SolarizedDarkTheme returns a Theme tuned for Solarized Dark terminals.
func SolarizedLightTheme ¶ added in v0.2.0
func SolarizedLightTheme() Theme
SolarizedLightTheme returns a Theme tuned for Solarized Light terminals.
func (Theme) GlamourOption ¶
func (t Theme) GlamourOption() glamour.TermRendererOption
GlamourOption returns a Glamour renderer option that applies this theme.
func (Theme) GlamourStyleJSON ¶
GlamourStyleJSON returns a Glamour JSON style config derived from Theme for the current terminal (light/dark, color depth, etc).
func (Theme) RenderError ¶
func (Theme) RenderHeading ¶
RenderHeading renders heading text with the optional prefix applied.
func (Theme) RenderInfo ¶
func (Theme) RenderSuccess ¶
func (Theme) RenderWarning ¶
func (Theme) ResolveColor ¶
func (t Theme) ResolveColor(role Role) lipgloss.AdaptiveColor
ResolveColor maps a semantic role to the theme color best suited for it. If a role does not have a dedicated mapping it falls back to TextNormal.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
all-libraries
command
|
|
|
basic
command
|
|
|
brand-colors
command
|
|
|
custom-theme
command
|
|
|
presets
command
|