theme

package
v0.11.15 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package theme provides color palettes for syntax highlighting.

Index

Constants

View Source
const DefaultEnvPrefix = "CLOG"

DefaultEnvPrefix is the default environment variable prefix.

Variables

This section is empty.

Functions

func SetEnvPrefix added in v0.10.0

func SetEnvPrefix(prefix string)

SetEnvPrefix sets a custom environment variable prefix. The prefix is process-wide and shared with root clog.

theme.SetEnvPrefix("MYAPP")
// Now checks MYAPP_THEME_LIGHT/MYAPP_THEME_DARK first, then CLOG_THEME_LIGHT/CLOG_THEME_DARK

Types

type Background added in v0.10.0

type Background int

Background describes the terminal background a theme is designed for.

const (
	BackgroundUnspecified Background = iota
	BackgroundLight
	BackgroundDark
)

func DetectBackground added in v0.10.0

func DetectBackground(out *os.File) (Background, bool)

DetectBackground queries a terminal for its background color.

func (Background) String added in v0.10.0

func (b Background) String() string

type Pair added in v0.10.0

type Pair struct {
	Light    *Theme
	Dark     *Theme
	Fallback Background
}

Pair holds the light and dark themes an application supports.

func DefaultPair added in v0.10.0

func DefaultPair(opts ...PairOption) *Pair

DefaultPair returns clog's built-in light/dark theme pair.

func FromEnv added in v0.10.0

func FromEnv(opts ...PairOption) (*Pair, error)

FromEnv resolves theme configuration from the environment.

Precedence:

  1. <PREFIX>_THEME selects an explicit theme, wrapped via Single so the same theme applies regardless of the terminal background.
  2. <PREFIX>_THEME_LIGHT and <PREFIX>_THEME_DARK select a light/dark pair.

It returns (nil, nil) when no theme variables are set. A set-but-invalid value returns an error.

func MustPair added in v0.10.0

func MustPair(light, dark *Theme, opts ...PairOption) *Pair

MustPair creates a theme pair and panics if it is invalid.

func NewPair added in v0.10.0

func NewPair(light, dark *Theme, opts ...PairOption) (*Pair, error)

NewPair creates a theme pair with one light theme and one dark theme.

func PairFromEnv added in v0.10.0

func PairFromEnv(opts ...PairOption) (*Pair, error)

PairFromEnv builds a theme pair from <PREFIX>_THEME_LIGHT and <PREFIX>_THEME_DARK.

func Single added in v0.11.0

func Single(t *Theme) *Pair

Single returns a Pair that renders t on both light and dark backgrounds, bypassing the light/dark validation that NewPair performs. Background detection still runs but has no visible effect.

func (*Pair) Auto added in v0.10.0

func (p *Pair) Auto(files ...*os.File) *Theme

Auto selects from the pair using the terminal background. Defaults to os.Stdout if no files are provided. All provided files must report the same background, otherwise the pair fallback is used.

func (*Pair) ForBackground added in v0.10.0

func (p *Pair) ForBackground(bg Background) *Theme

ForBackground returns the theme matching bg.

func (*Pair) ForTerminal added in v0.10.0

func (p *Pair) ForTerminal(out *os.File) *Theme

ForTerminal queries out and returns the theme matching its terminal background.

type PairOption added in v0.10.0

type PairOption func(*Pair)

PairOption configures a theme Pair.

func WithFallback added in v0.10.0

func WithFallback(bg Background) PairOption

WithFallback sets the background used when terminal detection is unavailable.

type Theme

type Theme struct {

	// Background declares the terminal background this theme is designed for.
	Background Background

	Accent     color.Color // type-level identifiers (block types, table headers, datetime, anchors)
	BoolFalse  color.Color // false, no, off
	BoolTrue   color.Color // true, yes, on
	Comment    color.Color // comments, null, tags
	Foreground color.Color // punctuation, structural tokens
	Key        color.Color // mapping/attribute keys
	Number     color.Color // numeric values
	Secondary  color.Color // secondary keys (nested keys)
	String     color.Color // string values
	// contains filtered or unexported fields
}

Theme defines a named color palette for syntax highlighting.

func Auto added in v0.10.0

func Auto(files ...*os.File) *Theme

Auto selects from clog's built-in themes using the terminal background. Defaults to os.Stdout if no files are provided.

func CatppuccinFrappe

func CatppuccinFrappe() *Theme

CatppuccinFrappe returns the Catppuccin Frappe (dark) color theme.

func CatppuccinLatte

func CatppuccinLatte() *Theme

CatppuccinLatte returns the Catppuccin Latte (light) color theme.

func CatppuccinMacchiato

func CatppuccinMacchiato() *Theme

CatppuccinMacchiato returns the Catppuccin Macchiato (dark) color theme.

func CatppuccinMocha

func CatppuccinMocha() *Theme

CatppuccinMocha returns the Catppuccin Mocha (dark) color theme.

func Dark added in v0.10.0

func Dark() *Theme

Dark returns clog's default dark-background color theme.

This intentionally preserves the colors that clog used before light/dark theme selection was added.

func Dracula

func Dracula() *Theme

Dracula returns the Dracula color theme.

func Light added in v0.10.0

func Light() *Theme

Light returns clog's default light-background color theme.

func Monokai

func Monokai() *Theme

Monokai returns the Monokai color theme.

func (*Theme) MarshalText added in v0.10.0

func (t *Theme) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Theme) Name added in v0.10.0

func (t *Theme) Name() string

Name returns the preset name for built-in themes, or "custom" for themes that were modified programmatically.

func (*Theme) UnmarshalText added in v0.10.0

func (t *Theme) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

Jump to

Keyboard shortcuts

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