themes

package
v0.0.0-...-1aa240f Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package themes discovers, renders, and installs gowall theme templates.

Index

Constants

This section is empty.

Variables

View Source
var BuiltinTemplates = []BuiltinTemplate{
	{ID: "alacritty", EmbedPath: "alacritty.toml.tmpl", DefaultOutput: "$HOME/.config/alacritty/colors.toml"},
	{ID: "polybar", EmbedPath: "polybar/colors.ini.tmpl", DefaultOutput: "$HOME/.config/polybar/colors.ini"},
	{ID: "rofi", EmbedPath: "rofi/color.rasi.tmpl", DefaultOutput: "$HOME/.config/rofi/color.rasi"},
	{ID: "bspwmrc", EmbedPath: "bspwmrc.tmpl", DefaultOutput: "$HOME/.config/bspwm/bspwmrc"},
	{ID: "gtk", EmbedPath: "gtk.css.tmpl", DefaultOutput: "$HOME/.config/gtk-4.0/colors.css"},
	{ID: "vscode", EmbedPath: "vscode.json.tmpl", DefaultOutput: "$HOME/.config/Code/User/settings.json"},
}

BuiltinTemplates is the registry of all embedded templates. Add new entries here and ensure the .tmpl file is included in the go:embed directive above.

Functions

func Apply

func Apply(id string, data ThemeData) error

Apply renders the template identified by id from $HOME/.config/gowall/templates/ and writes the result to the target path declared in the template's # target: comment. ThemeData is required for rendering.

func ApplyEmbedded

func ApplyEmbedded(name, outputPath string, data ThemeData) error

ApplyEmbedded renders a template embedded in the binary. name is the path inside the embed (e.g. "alacritty.toml.tmpl", "polybar/colors.ini.tmpl"). Templates are embedded in the binary; no external template files are required.

func ApplyTemplate

func ApplyTemplate(templatePath, outputPath string, data ThemeData) error

ApplyTemplate renders a template from the filesystem (for tests or custom paths).

func EnsureTemplatesInstalled

func EnsureTemplatesInstalled() error

EnsureTemplatesInstalled copies bundled templates to $HOME/.config/gowall/templates/ if that directory does not already exist. It is idempotent: if the dir exists, no-op.

func ParseTargetComment

func ParseTargetComment(templateContent string) (targetPath, body string, err error)

ParseTargetComment reads template headers and returns the target path and body. Returns an error if no "# target:" header is present.

func RenderEmbedded

func RenderEmbedded(name string, data ThemeData) (string, error)

RenderEmbedded renders an embedded template to a string without writing to disk.

func RenderTemplate

func RenderTemplate(raw string, data ThemeData) (string, error)

RenderTemplate renders a template from a raw string (e.g. a user-defined template loaded from disk) to a string without writing to disk.

func TemplateBodyForExecute

func TemplateBodyForExecute(templateContent string) string

TemplateBodyForExecute returns content suitable for text/template.Parse. All leading "# target:" and "# name:" header lines are stripped so they are not written to generated config files.

func TemplateVariableHelp

func TemplateVariableHelp() string

TemplateVariableHelp returns documentation for template authors (variables available in .tmpl files).

Types

type BuiltinTemplate

type BuiltinTemplate struct {
	ID            string // e.g. "alacritty"
	EmbedPath     string // path in embed FS
	DefaultOutput string // path with $HOME expanded (e.g. "$HOME/.config/alacritty/colors.toml")
}

BuiltinTemplate defines a built-in template (embedded in the binary).

func BuiltinByID

func BuiltinByID(id string) *BuiltinTemplate

BuiltinByID returns the builtin template for id, or nil if not found.

type Template

type Template struct {
	ID         string
	SourcePath string // filesystem path to the .tmpl file
	TargetPath string // expanded target path from # target: comment
	IsBuiltin  bool
}

Template describes a discovered template (either builtin or user-defined).

func DiscoverTemplates

func DiscoverTemplates() ([]Template, error)

DiscoverTemplates reads all *.tmpl files from $HOME/.config/gowall/templates/ and returns a Template slice. Returns an empty slice (no error) if the directory does not exist.

type TemplateHeaders

type TemplateHeaders struct {
	Target string // expanded path from "# target: <path>"; empty if absent
	Name   string // display name from "# name: <name>"; empty if absent
	Body   string // template content after the header block
}

TemplateHeaders holds metadata parsed from the leading comment block of a template file.

func ParseTemplateHeaders

func ParseTemplateHeaders(content string) TemplateHeaders

ParseTemplateHeaders scans leading lines of content for "# target: " and "# name: " comments in any order, stopping at the first line that does not match a known header. All matched header lines are stripped from Body.

type ThemeData

type ThemeData struct {
	Background    string   // hex without # (e.g. "1a1a1a")
	Foreground    string   // hex
	Ansi          []string // 16 elements: [0]=black .. [7]=white, [8]=bright black .. [15]=bright white
	Tones         []string // 16 steps dark→light (from image palette)
	TonesFromANSI []string // 16 steps from retoned ANSI; only non-nil when -retone-ansi (or -ansi-colors) was used
}

ThemeData holds all color values rendered into theme templates.

func LoadColorReferenceFile

func LoadColorReferenceFile(path string) (ThemeData, error)

LoadColorReferenceFile reads and parses a color reference file.

func ParseColorReference

func ParseColorReference(data string) (ThemeData, error)

ParseColorReference parses a Gowall Color Reference document (same format as exportColorReference writes). Lines starting with # are comments except for assignment lines that begin with a dot. Hex may include or omit a leading #.

Jump to

Keyboard shortcuts

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