Help us shape the future of Go! Take the 2026 Go Developer Survey

themefile

package
v0.19.12 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package themefile is the pi theme JSON resource format: parsing, validation, variable resolution, and path discovery. It is headless: the agent resource loader and HTML export read it, and agent/modes/theme renders it.

Index

Constants

This section is empty.

Variables

View Source
var RequiredColors = []string{
	"accent", "border", "borderAccent", "borderMuted", "success", "error", "warning", "muted", "dim", "text", "thinkingText",
	"selectedBg", "userMessageBg", "userMessageText", "customMessageBg", "customMessageText", "customMessageLabel", "toolPendingBg", "toolSuccessBg", "toolErrorBg", "toolTitle", "toolOutput",
	"mdHeading", "mdLink", "mdLinkUrl", "mdCode", "mdCodeBlock", "mdCodeBlockBorder", "mdQuote", "mdQuoteBorder", "mdHr", "mdListBullet",
	"toolDiffAdded", "toolDiffRemoved", "toolDiffContext", "syntaxComment", "syntaxKeyword", "syntaxFunction", "syntaxVariable", "syntaxString", "syntaxNumber", "syntaxType", "syntaxOperator", "syntaxPunctuation",
	"thinkingOff", "thinkingMinimal", "thinkingLow", "thinkingMedium", "thinkingHigh", "thinkingXhigh", "bashMode",
}

RequiredColors are the tokens every theme file must define.

Functions

func ANSI256ToHex

func ANSI256ToHex(index int) string

ANSI256ToHex maps a 256-color palette index to its xterm hex value.

func CleanPath

func CleanPath(path string) string

CleanPath trims path and resolves it like upstream's resolvePath.

func Discover

func Discover(cwd string, paths []string) ([]*Theme, []Diagnostic)

Discover loads the themes under paths (relative ones resolved against cwd): first name wins, and diagnostics list load warnings before collisions.

func HexColors

func HexColors(colors map[string]Color, defaultColor string) map[string]string

HexColors renders colors as CSS hex, dropping entries that do not render.

func ParseHex

func ParseHex(value string) (int, int, int, error)

ParseHex parses a #rrggbb color.

func ResolvePaths

func ResolvePaths(paths []string, base string) []string

ResolvePaths cleans paths, joining relative ones onto base.

Types

type Collision

type Collision struct {
	ResourceType string
	Name         string
	WinnerPath   string
	LoserPath    string
}

type Color

type Color struct {
	Index *int
	Text  string
}

Color is a resolved theme color: a 256-color palette index, or hex text where "" means the terminal default.

func (Color) Hex

func (color Color) Hex(defaultColor string) (string, error)

Hex renders the color as CSS hex; the terminal default becomes defaultColor.

type ColorValue

type ColorValue struct {
	String *string
	Index  *int
}

ColorValue is a theme JSON color: #rgb/#rrggbb, oklch(), okhsl(), a variable name, "" for the terminal default, or a 256-color index.

func (*ColorValue) UnmarshalJSON

func (value *ColorValue) UnmarshalJSON(data []byte) error

type Diagnostic

type Diagnostic struct {
	Type      string
	Path      string
	Message   string
	Collision *Collision
}

func CollisionDiagnostic

func CollisionDiagnostic(name, winnerPath, loserPath string) Diagnostic

CollisionDiagnostic reports loser losing its name to an earlier winner.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader walks theme paths in pi's discovery order. Each root is walked once; unreadable, missing, or invalid entries become warnings, and every parsed theme goes to the caller, which owns name collisions.

func (*Loader) LoadDefaultDirectory

func (loader *Loader) LoadDefaultDirectory(path string, add func(*Theme))

LoadDefaultDirectory walks path only when it is an existing directory.

func (*Loader) LoadPaths

func (loader *Loader) LoadPaths(paths []string, add func(*Theme))

func (*Loader) Warnings

func (loader *Loader) Warnings() []Diagnostic

Warnings returns the load warnings in discovery order.

type Theme

type Theme struct {
	Name string
	// Appearance is the theme's declared "dark" or "light" look, if any.
	Appearance string
	SourcePath string
	// Keys are the color tokens the file defines, in file order.
	Keys   []string
	Colors map[string]Color
	Export map[string]Color
}

Theme is a parsed theme resource with every color reference resolved.

func Parse

func Parse(label string, data []byte) (*Theme, error)

Parse decodes and validates one theme file. label names it in errors.

Jump to

Keyboard shortcuts

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