theme

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package theme holds rexuikit's semantic colour tokens.

A Theme is a plain value: there is no package-level theme variable and no setter, so two surfaces in one process (or two tests in parallel) can use different themes without racing. Components receive a Theme and derive every style from it through On, which sets foreground and background together. A style that sets only a foreground leaves the cell on the terminal's default background, and inside a Rex floating layer that cell shows the terminal underneath; On makes that mistake unwritable.

First frame and re-theming

Dark is the first-frame default. The terminal's real background reaches a bubbletea program as a tea.BackgroundColorMsg, and bubbletea v2 sends it only when asked: a program that wants FromBackground must return tea.RequestBackgroundColor from Init. The reply is an OSC 11 answer read off the terminal, so it arrives after the first frame has been drawn. The first frame is therefore always drawn with Dark, and a later re-theme (FromBackground on the message's colour) is accepted as a visible one-off repaint rather than avoided by blocking the first paint. Whether a Rex layer program receives that OSC 11 reply at all is a Rex behaviour recorded by W1.T2 in docs/rex-behaviors.md; when it does not, the program simply stays on Dark.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contrast

func Contrast(a, b color.Color) float64

Contrast is WCAG 2.1's contrast ratio between two colours, 1 (identical) to 21 (black on white).

Types

type Theme

type Theme struct {
	// Surface is the base background every component sits on.
	Surface color.Color
	// Well is the raised background of an input field or hint bar.
	Well color.Color
	// Text is the primary foreground.
	Text color.Color
	// Muted is the secondary foreground: hints, placeholders, subtitles.
	Muted color.Color
	// Accent marks focus and the primary action.
	Accent color.Color
	// Danger marks errors and destructive actions.
	Danger color.Color
	// Border is the rule colour for the opt-in bordered card and dividers.
	Border color.Color

	// Panel is the raised pane background of a status dashboard: lighter than
	// Surface in Dark, a step darker in Light. Text, Muted and the status
	// colours clear WCAG AA on it as well as on Surface.
	Panel color.Color
	// Strip is the header strip background; StripText is its foreground.
	Strip     color.Color
	StripText color.Color
	// Selection is the background of the selected row; SelectionText is the
	// foreground drawn on it.
	Selection     color.Color
	SelectionText color.Color
	// OnAccent is the foreground for text drawn on an Accent background, such
	// as a focused button.
	OnAccent color.Color
	// Faint is a decorative foreground for rules and separators. It is not
	// held to WCAG AA, so never use it for text a reader must read.
	Faint color.Color
	// Need marks a session that needs the user (orange), Work one in
	// progress (blue), Done one that finished (green), and Meta secondary
	// metadata (violet). Danger already covers bad.
	Need color.Color
	Work color.Color
	Done color.Color
	Meta color.Color
}

Theme is a set of semantic colour tokens. Zero value is not usable: build one with Dark, Light or FromBackground.

func Dark

func Dark() Theme

Dark is the default theme and the first-frame default (see the package comment). Its values are the native form spike's palette, except Muted: the spike's #7f849c is 4.44:1 on Surface and 3.76:1 on Well, under WCAG AA, so it is lifted to #9399b2.

func FromBackground

func FromBackground(bg color.Color) Theme

FromBackground picks Light for a light terminal background and Dark otherwise, by relative luminance. The threshold is the luminance at which black and white text have equal contrast (about 0.179), so a mid-grey background goes to whichever theme reads better on it. A nil colour, the state before any BackgroundColorMsg, yields Dark.

func Light

func Light() Theme

Light is the light counterpart of Dark: the same hues, darkened until every text token clears WCAG AA (4.5:1) on both Surface and Well.

func (Theme) Body

func (t Theme) Body() lipgloss.Style

Body is the style for ordinary text: Text on Surface.

func (Theme) On

func (t Theme) On(fg, bg color.Color) lipgloss.Style

On returns a style with foreground fg on background bg. Every component style goes through this so no cell is left on the default background.

Jump to

Keyboard shortcuts

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