theme

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package theme provides color theming for PuzzleTea. It loads terminal color schemes from an embedded JSON file and exposes a semantic Palette derived from the active theme's 16-color ANSI palette.

Index

Constants

View Source
const DefaultThemeName = "PuzzleTea Default"

DefaultThemeName is the name of the built-in earth-tone palette that ships with PuzzleTea. When no theme is configured, this palette is active.

Variables

View Source
var MaxNameLen int

MaxNameLen is the length of the longest theme name (including the default). Useful for sizing UI elements like the theme picker list.

Functions

func Apply

func Apply(name string) error

Apply activates the named theme. An empty name applies the built-in default. Returns an error if the theme name is not found.

func Blend

func Blend(a, b color.Color, t float64) color.Color

Blend returns a color that is t fraction of the way from a toward b. t=0 returns a, t=1 returns b. Used to derive muted background colors from foreground accent colors.

func MidTone

func MidTone(a, b color.Color) color.Color

MidTone returns a color perceptually halfway between a and b by blending their sRGB channels. This produces a muted tone suitable for dim/secondary text that is guaranteed to sit between the two anchors.

func PreviewPanel

func PreviewPanel(themeName string, height int) string

PreviewPanel renders a visual color preview for the named theme. It shows labeled swatches for the 16 ANSI colors, background/foreground, and the semantic roles.

func TextOnBG

func TextOnBG(bg color.Color) color.Color

TextOnBG returns the current palette's FG or BG color — whichever has better contrast against bg. This is useful for choosing readable text over an arbitrary background (e.g. colored rectangles in shikaku).

func ThemeNames

func ThemeNames() []string

ThemeNames returns the list of all theme names, with the default first.

Types

type Palette

type Palette struct {
	// Surfaces
	BG      color.Color // main background (theme Background)
	FG      color.Color // primary text (theme Foreground)
	Surface color.Color // subtle elevation (crosshair BG tint)

	// Brand / accent  (FG-role from ANSI)
	Accent     color.Color // primary accent (ANSI 3 — yellow)
	AccentSoft color.Color // muted accent (ANSI 11 — brightYellow)
	AccentText color.Color // text on AccentBG (ANSI 7 — white)

	// Text
	TextDim color.Color // secondary / muted text (derived)

	// Chrome
	Border color.Color // borders, separators (ANSI 0 — black)

	// Game FG-role tokens  (all from ANSI slots, enforced against BG)
	Success       color.Color // success/solved FG text (ANSI 2 — green)
	SuccessBorder color.Color // solved border FG (ANSI 10 — brightGreen)
	SolvedFG      color.Color // high-contrast text on state BGs (ANSI 15 — brightWhite)
	Error         color.Color // conflict/error FG text (ANSI 1 — red)
	Info          color.Color // hints, informational text (ANSI 4 — blue)
	Given         color.Color // immutable/provided cell FG (ANSI 5 — purple)
	Linked        color.Color // connected/related element FG (ANSI 6 — cyan)
	Highlight     color.Color // selection/highlight FG (ANSI 14 — brightCyan)
	Secondary     color.Color // second value type (ANSI 12 — brightBlue)
	Tertiary      color.Color // third differentiator (ANSI 13 — brightPurple)

	// Derived background-role tokens  (blended, not from ANSI slots)
	AccentBG    color.Color // cursor / active element BG
	SuccessBG   color.Color // solved cell BG
	ErrorBG     color.Color // conflict cell BG
	SelectionBG color.Color // drag / selection BG
	HighlightBG color.Color // adjacent / neighbor highlight BG

	// Full 16-color ANSI palette for puzzle-specific use (e.g. shikaku rects).
	// Order: black, red, green, yellow, blue, purple, cyan, white,
	//        brightBlack..brightWhite.
	ANSI [16]color.Color
}

Palette holds the semantic color tokens derived from a terminal color scheme. Every style in the application reads from the active palette via Current.

All ANSI-sourced tokens are foreground/text-role colors. Background-role colors (AccentBG, SuccessBG, ErrorBG, SelectionBG, HighlightBG) are derived by blending a FG-role color toward BG or Surface, so they always match the theme's luminance range.

func Current

func Current() Palette

Current returns the active palette. Safe for concurrent use.

func (Palette) ThemeColors added in v1.6.0

func (p Palette) ThemeColors() []color.Color

ThemeColors returns a curated slice of distinct, colorful palette colors suitable for differentiating themed UI elements (cards, hover bars, puzzle regions, etc). The colors are drawn from chromatic ANSI slots (skipping black/white/gray), giving up to 10 visually distinct options per theme.

type Theme

type Theme struct {
	Name                string `json:"name"`
	Black               string `json:"black"`
	Red                 string `json:"red"`
	Green               string `json:"green"`
	Yellow              string `json:"yellow"`
	Blue                string `json:"blue"`
	Purple              string `json:"purple"`
	Cyan                string `json:"cyan"`
	White               string `json:"white"`
	BrightBlack         string `json:"brightBlack"`
	BrightRed           string `json:"brightRed"`
	BrightGreen         string `json:"brightGreen"`
	BrightYellow        string `json:"brightYellow"`
	BrightBlue          string `json:"brightBlue"`
	BrightPurple        string `json:"brightPurple"`
	BrightCyan          string `json:"brightCyan"`
	BrightWhite         string `json:"brightWhite"`
	Background          string `json:"background"`
	Foreground          string `json:"foreground"`
	CursorColor         string `json:"cursorColor,omitempty"`
	SelectionBackground string `json:"selectionBackground,omitempty"`
	Meta                struct {
		IsDark bool `json:"isDark"`
	} `json:"meta"`
}

Theme represents a terminal color scheme with the standard 16 ANSI colors plus background, foreground, and cursor colors.

func AllThemes

func AllThemes() []Theme

AllThemes returns every available theme.

func LookupTheme

func LookupTheme(name string) *Theme

LookupTheme returns the theme with the given name, or nil if not found.

func (Theme) Palette

func (t Theme) Palette() Palette

Palette returns the semantic color palette derived from this theme.

Jump to

Keyboard shortcuts

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