theme

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package theme provides the Catppuccin palettes used to color the interactive prompt.

It is opt-in: a project selects a flavor via the `prompt.theme` key in .posh.yaml, and without it posh keeps its previous, unthemed colors.

Index

Constants

View Source
const DefaultFlavor = FlavorMocha

DefaultFlavor is used when nothing selects a flavor and auto-detection does not produce an answer.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capability

type Capability int

Capability is how much color the terminal can render.

const (
	CapabilityNone Capability = iota
	Capability16
	Capability256
	CapabilityTrueColor
)

func DetectCapability

func DetectCapability() Capability

DetectCapability reports what the current terminal supports.

This exists because neither pterm nor gookit degrades on its own: gookit's RenderCode only checks whether color is enabled at all, and otherwise emits whatever escape it was handed. A truecolor sequence therefore reaches a 256-color terminal verbatim and renders as garbage. Every color this package emits is chosen against this value instead.

func (Capability) String

func (c Capability) String() string

type Flavor

type Flavor string

Flavor is one of the four Catppuccin palettes.

const (
	FlavorMocha     Flavor = "mocha"
	FlavorMacchiato Flavor = "macchiato"
	FlavorFrappe    Flavor = "frappe"
	FlavorLatte     Flavor = "latte"
)

func Flavors

func Flavors() []Flavor

Flavors returns every flavor, dark ones first.

func ParseFlavor

func ParseFlavor(v string) (Flavor, error)

ParseFlavor resolves a flavor name case-insensitively.

func (Flavor) IsDark

func (f Flavor) IsDark() bool

IsDark reports whether the flavor is intended for a dark terminal background. Only Latte is light.

func (Flavor) String

func (f Flavor) String() string

type Option

type Option func(*Theme) error

func WithCapability

func WithCapability(v Capability) Option

WithCapability pins the color tier instead of detecting it. Intended for tests: production code should let New detect the terminal.

func WithFlavor

func WithFlavor(v Flavor) Option

type Role

type Role int

Role is a semantic slot in a palette rather than a Catppuccin color name.

Call sites ask for meaning ("this is an error") instead of a color, so swapping the palette — in particular flipping between a dark and a light flavor — needs no call-site edits. It also keeps the palette data unexported: naming Mauve in a public API would promise a distinction the 16-color prompt tier cannot keep, since Mocha's Mauve and Lavender collapse to the same ANSI slot.

const (
	RoleText Role = iota
	RoleMuted
	RolePrimary
	RoleSecondary
	RoleSuccess
	RoleWarning
	RoleError
	RoleInfo
	RoleDebug
)

func Roles

func Roles() []Role

Roles returns every role, in declaration order. Used by tests to assert that each palette covers the full set.

func (Role) String

func (r Role) String() string

type Theme

type Theme struct {
	// contains filtered or unexported fields
}

Theme is a resolved palette: a flavor plus the terminal capability its colors have been projected onto.

func New

func New(opts ...Option) (*Theme, error)

func Resolve

func Resolve(flavor string) (*Theme, error)

Resolve builds the theme for a configured flavor name.

An empty name means no theme was configured and returns nil, which callers treat as "keep the previous, unthemed behavior" rather than as an error. An unrecognized name is an error: it is a typo in something the user wrote, and silently rendering a different theme would hide it.

func (*Theme) Capability

func (t *Theme) Capability() Capability

func (*Theme) Flavor

func (t *Theme) Flavor() Flavor

func (*Theme) Hex

func (t *Theme) Hex(r Role) string

Hex returns the role's exact Catppuccin value.

The prompt cannot render it — see Prompt — but it is the palette's source of truth and is exposed for commands that print their own colors.

func (*Theme) IsDark

func (t *Theme) IsDark() bool

func (*Theme) Prompt

func (t *Theme) Prompt(r Role) goprompt.Color

Prompt returns the role as one of go-prompt's 16 ANSI colors.

The prompt is capped at 16 colors, so this is an approximation. It is hand-mapped rather than derived: gookit's nearest-basic conversion collapses almost every Mocha role onto white, which would erase both the roles and the dark/light distinction in precisely the tier that cannot afford to lose them.

Jump to

Keyboard shortcuts

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