theme

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package theme provides theme file parsing and serialization for revdiff color palettes. Theme files use INI format with comment-based metadata (# name: ..., # description: ...).

Index

Constants

View Source
const DefaultThemeName = "revdiff"

DefaultThemeName is the name of the built-in default theme.

Variables

This section is empty.

Functions

func ActiveName added in v0.15.0

func ActiveName(name string) string

ActiveName returns the theme name, defaulting to the built-in default when empty.

func ColorKeys

func ColorKeys() []string

ColorKeys returns the ordered list of recognized color key names.

func Dump

func Dump(t Theme, w io.Writer) error

Dump writes a theme file to w from the given Theme. Colors are written in the canonical order defined by ColorKeys().

func Gallery() (map[string]Theme, error)

Gallery returns all themes from the embedded gallery, keyed by filename. Results are cached after the first call since the embedded FS is immutable. Each call returns a deep copy so callers can mutate the result safely.

func GalleryNames added in v0.15.0

func GalleryNames() ([]string, error)

GalleryNames returns sorted names of all themes in the embedded gallery.

func InitAll added in v0.15.0

func InitAll(themesDir string) error

InitAll writes all gallery themes to the given directory, creating it if needed. Always overwrites files matching gallery theme names; does not touch user-added files.

func InitBundled

func InitBundled(themesDir string) error

InitBundled writes bundled theme files (marked bundled: true in gallery) to the given directory, creating it if needed. Always overwrites files matching bundled theme names; does not touch user-added files.

func InitNames added in v0.15.0

func InitNames(themesDir string, names []string) error

InitNames writes specific named themes from the gallery to the given directory. Returns an error if any name is not found in the gallery.

func Install added in v0.15.0

func Install(args []string, themesDir string, validateChroma func(string) bool, stdout io.Writer) error

Install installs themes from gallery names or local file paths. Validates all gallery names upfront before performing any installs to prevent partial state.

func List

func List(themesDir string) ([]string, error)

List returns sorted names of theme files in the given directory. Returns an empty list if the directory does not exist.

func OptionalColorKeys

func OptionalColorKeys() map[string]bool

OptionalColorKeys returns the set of color keys that may be omitted from theme files. these correspond to CLI flags with no default value (terminal background is used instead).

func PrintList added in v0.15.0

func PrintList(themesDir string, w io.Writer) error

PrintList prints all known theme names, one per line. Order: default theme first, then local, then bundled, then other gallery — sorted within each group.

Types

type Theme

type Theme struct {
	Name        string
	Description string
	Author      string
	Bundled     bool
	ChromaStyle string
	Colors      map[string]string // keys include the "color-" prefix, matching ini-name tags exactly (e.g. "color-accent")
}

Theme represents a color theme with metadata and color key-value pairs.

func GalleryTheme added in v0.15.0

func GalleryTheme(name string) (Theme, error)

GalleryTheme returns a single theme from the embedded gallery by name.

func Load

func Load(name, themesDir string) (Theme, error)

Load reads a theme by name. It first checks the local themes directory for a user-customized copy, then falls back to the embedded gallery. Name must be a plain filename without path separators or directory traversal components.

func Parse

func Parse(r io.Reader) (Theme, error)

Parse reads a theme file from r and returns the parsed Theme. Theme files use INI-style key=value pairs and comment metadata lines:

# name: theme-name
# description: one-line description
chroma-style = dracula
color-accent = #bd93f9

func (Theme) Clone added in v0.15.0

func (t Theme) Clone() Theme

Clone returns a deep copy of the theme so callers can mutate it safely.

type ThemeInfo added in v0.15.0

type ThemeInfo struct {
	Name      string
	InGallery bool // true if name exists in the embedded gallery
	Bundled   bool // true if gallery entry has bundled: true
	Local     bool // true if installed locally but not in gallery
}

ThemeInfo holds classification metadata for a theme in an ordered listing.

func ListOrdered added in v0.15.0

func ListOrdered(themesDir string) ([]ThemeInfo, error)

ListOrdered merges gallery and locally installed themes into a classified, deterministic list. Order: default theme first, then local-only (sorted), then bundled gallery (sorted), then other gallery (sorted).

Jump to

Keyboard shortcuts

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