theme

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 15 Imported by: ? modules, 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

fs_watch.go (pi: src/modes/interactive/theme — theme file watching).

pig keeps the poll-watcher implementation in codingagent/utils (pi keeps it in src/utils/fs-watch.ts, shared with the footer git watcher); these aliases preserve the theme package's internal call sites.

system_theme.go (pi: src/modes/interactive/theme/system-theme.ts) — the `system` theme: pi's colors derived from the terminal's own theme.

Every token belongs to a color family (its hue) and has contrast rules: it must reach a contrast level on the background and on the panels it is drawn on. Hue and saturation come from the terminal's palette color for the family's ANSI slot, or from the family's own hue when the terminal reports no palette. Lightness comes from the rules alone. Colors are built in OKHSL, whose saturation is relative to the sRGB gamut, and fade toward gray near black and white.

A contrast level is a target-lightness curve: the OKLab lightness a token needs, given the lightness of the surface below it. The curves were fitted to the reference theme design from the "Pi themes: system and light/dark" review. On dark backgrounds they aim for nearly fixed lightness; on light backgrounds the required difference grows as the background darkens.

Depending on what the terminal reports, the theme is generated in one of three tiers:

  • background and palette: hues from the palette, lightness from the background;
  • background only: the families' own hues, lightness from the background;
  • nothing: ANSI palette indices and the default colors, which the terminal renders itself.

Package theme (pi: src/modes/interactive/theme/theme.ts) — the Theme class, color utilities, theme loading/registry, the global theme instance, terminal color/theme detection, HTML export helpers and the TUI theme adapters.

Declared deviations:

  • pi stores the global theme on globalThis (cross module-loader sharing); pig uses package state guarded by a mutex. Package-level functions (Fg/Bg/Bold/...) delegate to Current(), keeping call sites shaped like pi's `theme.fg(...)` proxy.
  • pi's chalk.bold/italic/... are hand-rolled ANSI here (repo-wide precedent: chalk is not ported; test_themes_test.go hand-writes level-3 bytes).
  • The theme file watcher polls the watched theme file (Go has no fs.watch); pi's dir watcher + filename filter collapses to a watched-file mtime poll. The 100ms reload debounce is preserved.
  • Validation is a hand-written equivalent of the TypeBox schema (model-config precedent). Missing-color diagnostics keep pi's formatting; other type-error wording is approximate (no pi test locks it).
  • Syntax highlighting delegates to codingagent/utils (chroma backend; see syntax_highlight.go for the deviation record).
  • Broken built-in theme JSON surfaces as a panic in InitTheme/SetTheme fallback paths, matching pi's synchronous throw out of the catch block (both are fatal at startup).
  • The v0.87.1-era terminal background detection family (TerminalThemeDetection/Source/Confidence, DetectTerminalBackgroundTheme/ForAuto, GetDefaultTheme, GetThemeForRgbColor) is removed with pi v0.99.1's #10067 rewrite: DetectTerminalTheme (background → light/dark report → COLORFGBG → dark) replaces it, and the controller queries terminal colors directly. pig's blocking-query deviations (see tui/terminal_query_deadlock_test.go) carry over to tui.QueryTerminalColors unchanged.
  • pig-only palette tweaks (user decision 2026-09-24, light.json's syntaxVariable/syntaxKeyword overrides) were dropped with the v0.99.1 builtin theme redesign: the OKHSL rewrite replaced pi's old palette entirely, so the override no longer applies to the same design (flag in the S10-3 handoff for re-evaluation).

theme_controller.go (pi: src/modes/interactive/theme/theme-controller.ts).

The controller declares a narrow TUI consumption-face interface (ThemeControllerTUI) instead of pi's full TUI type — repo precedent: ModelResolverRuntime. tui.TUI satisfies it; tests stub it.

pi's async controller methods (applyFromSettings/setThemeSetting) become blocking calls with error returns; the terminal color query is blocking (see the QueryTerminalColors dispatch-safety notes in tui/tui.go). waitForTerminalColors becomes WaitTerminalColors (blocking on a channel).

theme_json.go (pi: theme/theme-json.ts, v0.85.1) — theme JSON validation, kept out of `theme.go` on purpose.

pi moves full validation out of theme.ts so that presentations which only use built-in themes never pay the typebox import (~17 MB of module graph). `interactive-mode` installs this validator; anything that does not simply skips validation, as built-in themes already do. In Go the cost is a hand-written validator instead of typebox, but the seam is kept 1:1 so the consumption shape matches: theme.go's parseThemeJson consults the installed validator and otherwise performs a minimal structural check.

Index

Constants

View Source
const FSWatchRetryDelayMs = utils.FSWatchRetryDelayMs

FSWatchRetryDelayMs is pi's FS_WATCH_RETRY_DELAY_MS.

View Source
const SystemThemeName = "system"

SystemThemeName is the reserved name of the generated system theme (pi: SYSTEM_THEME_NAME).

Variables

View Source
var BuiltinThemeNames = []string{"dark", "light"}

BuiltinThemeNames lists the bundled theme JSONs (pi: dark / light).

View Source
var CloseWatcher = utils.CloseWatcher

CloseWatcher stops a watcher, ignoring nil and close errors (pi: closeWatcher).

View Source
var WatchWithErrorHandler = utils.WatchWithErrorHandler

WatchWithErrorHandler polls path for mtime/size changes and invokes onChange; poll-setup errors invoke onError and return nil.

Functions

func Bg

func Bg(color ThemeBg, text string) string

Bg colors text with the global theme (pi: theme.bg).

func Bold

func Bold(text string) string

Bold styles text with the global theme (pi: theme.bold).

func CurrentName

func CurrentName() string

CurrentName returns the active theme name ("" = unset; pi: currentThemeName module state, exposed for controller consumption).

func Fg

func Fg(color ThemeColor, text string) string

Fg colors text with the global theme (pi: theme.fg).

func FgOptional added in v1.0.1

func FgOptional(token, fallback ThemeColor, text string) string

FgOptional colors text with the token on the global theme when defined, else with the fallback token (pig-only).

func GetAvailableThemes

func GetAvailableThemes() []string

func GetEditorTheme

func GetEditorTheme() tui.EditorTheme

GetEditorTheme builds the editor theme (pi: getEditorTheme).

func GetLanguageFromPath

func GetLanguageFromPath(filePath string) (string, bool)

GetLanguageFromPath maps a file extension to a language identifier (pi: getLanguageFromPath).

func GetMarkdownTheme

func GetMarkdownTheme() tui.MarkdownTheme

GetMarkdownTheme builds the Markdown theme from the global theme (pi: getMarkdownTheme).

func GetResolvedThemeColors

func GetResolvedThemeColors(themeName string) map[string]string

GetResolvedThemeColors returns the resolved theme colors as CSS-compatible hex strings (pi: getResolvedThemeColors). Panics when the theme cannot be loaded, matching pi's unguarded loadTheme.

func GetSelectListTheme

func GetSelectListTheme() tui.SelectListTheme

GetSelectListTheme builds the select-list theme (pi: getSelectListTheme).

func GetSettingsListTheme

func GetSettingsListTheme() tui.SettingsListTheme

GetSettingsListTheme builds the settings-list theme (pi: getSettingsListTheme).

func HighlightCode

func HighlightCode(code string, lang string) []string

HighlightCode highlights code with syntax coloring based on language (pi: highlightCode).

func InitTheme

func InitTheme(themeName string, enableWatcher bool)

InitTheme loads and installs the named theme ("" = the system theme), falling back to the system theme silently (pi: initTheme). enableWatcher starts the custom-theme file watcher.

func Inverse

func Inverse(text string) string

Inverse styles text with the global theme (pi: theme.inverse).

func IsLightTheme

func IsLightTheme(themeName string) bool

IsLightTheme reports whether the named theme is light (pi: isLightTheme).

func Italic

func Italic(text string) string

Italic styles text with the global theme (pi: theme.italic).

func MarkTerminalColorsPending added in v1.0.0

func MarkTerminalColorsPending()

MarkTerminalColorsPending renders the system theme in grayscale until SetTerminalColors reports the terminal's colors (pi: markTerminalColorsPending).

func OnThemeChange

func OnThemeChange(callback func())

OnThemeChange registers the change callback (pi: onThemeChange).

func RelativeLuminance added in v1.0.0

func RelativeLuminance(c tui.RgbColor) float64

RelativeLuminance is the WCAG 2 relative luminance (pi: relativeLuminance).

func RequestTerminalColors added in v1.0.0

func RequestTerminalColors(ui TerminalColorQuerier, apply func(colors tui.TerminalColors)) tui.TerminalColors

RequestTerminalColors queries the terminal's colors and passes them to apply when the query completes or times out, and again if the terminal answers after the timeout. A failed query applies no colors. Settles after the first apply (pi: requestTerminalColors; pig blocks and returns the first result).

func ResolveThemeSetting

func ResolveThemeSetting(themeSetting string, terminalTheme TerminalTheme) (string, bool)

ResolveThemeSetting resolves a theme setting against the detected terminal appearance (pi: resolveThemeSetting).

func SetGlobalTheme

func SetGlobalTheme(t *Theme)

SetGlobalTheme installs a theme instance (pi: setGlobalTheme — private, exported for SetThemeInstance's cross-package consumers and tests).

func SetRegisteredThemes

func SetRegisteredThemes(themes []*Theme)

SetRegisteredThemes replaces the extension/theme-loader registered themes (pi: setRegisteredThemes).

func SetTerminalColorScheme added in v1.0.0

func SetTerminalColorScheme(scheme TerminalTheme)

SetTerminalColorScheme records the terminal's light/dark report, the fallback for terminals that do not report their background (pi: setTerminalColorScheme; "" unsets).

func SetTerminalColors added in v1.0.0

func SetTerminalColors(colors tui.TerminalColors)

SetTerminalColors records the terminal's reported colors. Themes use the default colors for tokens set to "" (terminal default); the system theme is generated from all of them. Ends the pending state (pi: setTerminalColors).

func SetThemeInstance

func SetThemeInstance(themeInstance *Theme)

SetThemeInstance installs a direct theme instance (pi: setThemeInstance).

func SetThemeJsonValidator

func SetThemeJsonValidator(validator ThemeJsonValidator)

SetThemeJsonValidator installs full theme validation (pi: setThemeJsonValidator). Without it, documents are accepted as-is, which is what built-in themes already do.

func Strikethrough

func Strikethrough(text string) string

Strikethrough styles text with the global theme (pi: theme.strikethrough).

func Underline

func Underline(text string) string

Underline styles text with the global theme (pi: theme.underline).

func WcagContrast added in v1.0.0

func WcagContrast(first, second tui.RgbColor) float64

WcagContrast is the WCAG 2 contrast ratio, 1-21 (pi: wcagContrast).

Types

type AutoThemePair

type AutoThemePair struct {
	LightTheme string
	DarkTheme  string
}

AutoThemePair is parseAutoThemeSetting's resolved pair.

func ParseAutoThemeSetting

func ParseAutoThemeSetting(themeSetting string) *AutoThemePair

ParseAutoThemeSetting parses "<light>/<dark>" theme settings (pi: parseAutoThemeSetting). Returns nil for unset/invalid settings.

type ColorMode

type ColorMode = tui.TerminalColorMode

ColorMode is the v0.87.1 pig-era alias for the TUI terminal color mode (kept for existing consumers; pi: TerminalColorMode).

const (
	ColorModeTruecolor ColorMode = tui.ColorModeTruecolorN
	ColorMode256       ColorMode = tui.ColorMode256color
)

type ColorValue

type ColorValue = any

ColorValue is a theme color value: a hex/oklch()/okhsl() string, a variable reference ("primary"), an empty string (terminal default), or a 256-color index (pi: ColorValue = string | int).

type InteractiveThemeController

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

InteractiveThemeController manages the global theme for the interactive session (pi: class InteractiveThemeController).

func NewInteractiveThemeController

func NewInteractiveThemeController(ui ThemeControllerTUI, options InteractiveThemeControllerOptions) *InteractiveThemeController

NewInteractiveThemeController builds the controller (pi: constructor).

func (*InteractiveThemeController) ApplyFromSettings

func (c *InteractiveThemeController) ApplyFromSettings()

ApplyFromSettings applies the theme setting now and queries the terminal's colors, which update the theme when they arrive. Theme pairs and the system theme follow terminal appearance changes (pi: applyFromSettings).

func (*InteractiveThemeController) DisableAutoSync

func (c *InteractiveThemeController) DisableAutoSync()

DisableAutoSync turns off light/dark auto sync (pi: disableAutoSync).

func (*InteractiveThemeController) Dispose

func (c *InteractiveThemeController) Dispose()

Dispose stops terminal appearance updates and drops the color-scheme listener subscription (pi: dispose).

func (*InteractiveThemeController) GetTerminalTheme

func (c *InteractiveThemeController) GetTerminalTheme() TerminalTheme

GetTerminalTheme returns the detected terminal appearance (pi: getTerminalTheme).

func (*InteractiveThemeController) GetThemeSelection

func (c *InteractiveThemeController) GetThemeSelection() (string, bool)

GetThemeSelection returns the effective theme setting (pi: getThemeSelection; second return false = undefined).

func (*InteractiveThemeController) Preview

func (c *InteractiveThemeController) Preview(themeSettingOrName string)

Preview applies a theme without persisting the selection (pi: preview).

func (*InteractiveThemeController) RebindTui

func (c *InteractiveThemeController) RebindTui()

RebindTui re-subscribes the color-scheme listener after a TUI swap (pi: rebindTui).

func (*InteractiveThemeController) SetThemeInstance

func (c *InteractiveThemeController) SetThemeInstance(themeInstance *Theme) ThemeResult

SetThemeInstance installs a direct theme instance (pi: setThemeInstance).

func (*InteractiveThemeController) SetThemeName

func (c *InteractiveThemeController) SetThemeName(themeName string, showError bool) ThemeResult

SetThemeName selects a theme explicitly (pi: setThemeName).

func (*InteractiveThemeController) SetThemeSetting

func (c *InteractiveThemeController) SetThemeSetting(themeSetting string)

SetThemeSetting persists and applies a theme setting (pi: setThemeSetting).

func (*InteractiveThemeController) WaitTerminalColors added in v1.0.0

func (c *InteractiveThemeController) WaitTerminalColors()

WaitTerminalColors blocks until the latest color query completed or timed out. Content that bakes theme colors into strings, such as the startup header, should be built after this. Terminals answer the DA1 request right after the color replies, so this only takes the full timeout when a terminal answers nothing (pi: waitForTerminalColors).

type InteractiveThemeControllerOptions

type InteractiveThemeControllerOptions struct {
	GetSettingsManager  func() ThemeSettingsManager
	ShowError           func(message string)
	OnChanged           func()
	InitialThemeSetting string
}

InteractiveThemeControllerOptions carries the constructor's callbacks (pi: options object; initialThemeSetting "" = undefined).

type PollWatcher

type PollWatcher = utils.PollWatcher

PollWatcher is pi's FSWatcher (pig: mtime/size polling watcher).

type RegisteredThemeEntry

type RegisteredThemeEntry struct {
	Name       string
	Theme      *Theme
	SourcePath string
}

RegisteredThemeEntry is one registeredThemes snapshot item.

type SetThemeResult

type SetThemeResult struct {
	Success bool
	Error   string
}

SetThemeResult is pi's { success: boolean; error?: string }.

func SetTheme

func SetTheme(name string, enableWatcher bool) SetThemeResult

SetTheme switches the global theme by name (pi: setTheme).

type SystemThemeColors added in v1.0.0

type SystemThemeColors struct {
	// Colors maps tokens to hex colors, ANSI palette indices, or "" for the
	// terminal default.
	Colors map[string]ColorValue
	// Dim lists foreground tokens rendered faint (SGR 2), for terminals that
	// did not report colors.
	Dim []ThemeColor
	// Appearance is the detected appearance; nil when the terminal reported
	// nothing (pi: appearance?).
	Appearance *TerminalTheme
}

SystemThemeColors is the generated system theme (pi: SystemThemeColors).

func GenerateSystemThemeColors added in v1.0.0

func GenerateSystemThemeColors(input SystemThemeInput) SystemThemeColors

GenerateSystemThemeColors generates the system theme's colors from the terminal's reported colors (pi: generateSystemThemeColors).

type SystemThemeInput added in v1.0.0

type SystemThemeInput struct {
	Foreground *tui.RgbColor
	Background *tui.RgbColor
	// Palette is ANSI colors 0-15.
	Palette []tui.RgbColor
	// Saturation is a multiplier from 0 (grayscale) to 1. The first frame
	// renders in grayscale until colors arrive. nil = 1.
	Saturation *float64
	// AppearanceHint is the appearance when the terminal did not report its
	// background, e.g. from its light/dark report or COLORFGBG. "" = unset.
	AppearanceHint TerminalTheme
}

SystemThemeInput carries the terminal's reported colors (pi: SystemThemeInput).

type TerminalColorQuerier added in v1.0.0

type TerminalColorQuerier interface {
	QueryTerminalColors(timeoutMs int, onLateReply func(colors tui.TerminalColors)) tui.TerminalColors
}

TerminalColorQuerier is the narrow face requestTerminalColors needs (pi passes the full TUI; pig narrows so the startup selectors can share the helper without a full controller TUI).

type TerminalTheme

type TerminalTheme string

TerminalTheme is "dark" | "light" (pi: TerminalTheme).

const (
	TerminalThemeDark  TerminalTheme = "dark"
	TerminalThemeLight TerminalTheme = "light"
)

func DetectColorFgBgTheme added in v1.0.0

func DetectColorFgBgTheme(lookup func(key string) string) TerminalTheme

DetectColorFgBgTheme reads dark or light from the `COLORFGBG` environment variable some terminals set (pi: detectColorFgBgTheme). The value is `fg;bg` or `fg;xpm;bg` (rxvt), where a field is an ANSI color index or `default` when the color is not in the palette. The index refers to the terminal's own palette, whose colors are unknown here, so it is classified by index like Vim does: 0-6 and 8 (bright black, e.g. Solarized Dark's background) are dark, 7 and 9-15 are light.

func DetectTerminalTheme added in v1.0.0

func DetectTerminalTheme(colors *tui.TerminalColors, reportedScheme TerminalTheme, lookup func(key string) string) TerminalTheme

DetectTerminalTheme reports whether the terminal is dark or light (pi: detectTerminalTheme). The background it renders decides, classified the same way the system theme does. Without a reported background: the terminal's light/dark report, then COLORFGBG, then dark.

func GetTerminalTheme added in v1.0.0

func GetTerminalTheme() TerminalTheme

GetTerminalTheme reports whether the terminal is dark or light, from everything it reported so far (pi: getTerminalTheme).

func TerminalAppearance added in v1.0.0

func TerminalAppearance(background tui.RgbColor, foreground *tui.RgbColor) TerminalTheme

TerminalAppearance reports whether a terminal is dark or light, from its reported colors: the direction of its own foreground when text can be readable that way, otherwise dark when white text has more contrast on the background than black text (pi: terminalAppearance).

type Theme

type Theme struct {

	// SourceInfo is assigned by the resource loader (pi: sourceInfo?).
	SourceInfo *utils.SourceInfo
	// contains filtered or unexported fields
}

Theme is the resolved theme (pi: class Theme).

func Current

func Current() *Theme

Current returns the active global theme. It panics when the theme has not been initialized, matching pi's proxy throw.

func GetThemeByName

func GetThemeByName(name string) *Theme

GetThemeByName loads a theme by name, returning nil when it cannot be loaded (pi: getThemeByName).

func LoadThemeFromPath

func LoadThemeFromPath(themePath string, mode tui.TerminalColorMode) (*Theme, error)

LoadThemeFromPath loads and validates a theme file (pi: loadThemeFromPath). mode "" = auto-detect from terminal capabilities.

func NewTheme

func NewTheme(fgColors map[string]ColorValue, bgColors map[string]ColorValue, mode tui.TerminalColorMode, options *ThemeOptions) (*Theme, error)

NewTheme builds a theme from resolved color values (pi: constructor). fgColors/bgColors values are string ("#hex"/"oklch(...)"/"okhsl(...)"/"" = terminal default) or int (256-color index).

func (*Theme) Appearance added in v1.0.0

func (t *Theme) Appearance() TerminalTheme

Appearance returns the background the theme is designed for: declared in the theme JSON, detected from its colors, or, for themes without usable colors, the terminal's appearance (pi: appearance getter).

func (*Theme) Bg

func (t *Theme) Bg(color ThemeBg, text string) string

Bg wraps text in the token's background color, resetting only the background (pi: bg).

func (*Theme) Bold

func (t *Theme) Bold(text string) string

Bold mirrors chalk.bold.

func (*Theme) Colors added in v1.0.0

func (t *Theme) Colors() map[ThemeToken]tui.Color

Colors returns concrete colors for all tokens. Tokens set to "" (terminal default) use the terminal's reported default colors, or a guess based on Appearance() when the terminal did not report them. Faint tokens are approximated by mixing their color toward the background (pi: colors getter).

func (*Theme) Fg

func (t *Theme) Fg(color ThemeColor, text string) string

Fg wraps text in the token's foreground color, resetting only the foreground (pi: fg). Faint tokens include SGR 2.

func (*Theme) FgOptional added in v1.0.1

func (t *Theme) FgOptional(token, fallback ThemeColor, text string) string

FgOptional colors text with the token when the theme defines it, else with the fallback token (pig-only: themes may define optional rule tokens such as userMessageRule / toolSuccessRule; older themes fall back to the state tokens).

func (*Theme) GetBashModeBorderColor

func (t *Theme) GetBashModeBorderColor() func(string) string

GetBashModeBorderColor returns the bash-mode border colorizer (pi: getBashModeBorderColor).

func (*Theme) GetBgAnsi

func (t *Theme) GetBgAnsi(color ThemeBg) string

GetBgAnsi returns the raw ANSI prefix for a background token (pi: getBgAnsi).

func (*Theme) GetColorMode

func (t *Theme) GetColorMode() tui.TerminalColorMode

GetColorMode returns the ANSI mode (pi: getColorMode).

func (*Theme) GetFgAnsi

func (t *Theme) GetFgAnsi(color ThemeColor) string

GetFgAnsi returns the opening escape sequence for a foreground token. Faint tokens include SGR 2, which `\x1b[22m` closes (pi: getFgAnsi).

func (*Theme) GetName

func (t *Theme) GetName() string

GetName returns the theme name ("" = unnamed, pi: name?).

func (*Theme) GetSourcePath

func (t *Theme) GetSourcePath() string

GetSourcePath returns the source path ("" = none, pi: sourcePath?).

func (*Theme) GetThinkingBorderColor

func (t *Theme) GetThinkingBorderColor(level agent.ThinkingLevel) func(string) string

GetThinkingBorderColor maps thinking levels to dedicated theme colors (pi: getThinkingBorderColor).

func (*Theme) HasFgToken added in v1.0.1

func (t *Theme) HasFgToken(color ThemeColor) bool

HasFgToken reports whether the theme defines the token (pig-only).

func (*Theme) Inverse

func (t *Theme) Inverse(text string) string

Inverse mirrors chalk.inverse.

func (*Theme) Italic

func (t *Theme) Italic(text string) string

Italic mirrors chalk.italic.

func (*Theme) Strikethrough

func (t *Theme) Strikethrough(text string) string

Strikethrough mirrors chalk.strikethrough.

func (*Theme) Style added in v1.0.0

func (t *Theme) Style(text string, options ThemeStyle) string

Style styles text with theme tokens or concrete colors plus attributes (pi: style).

func (*Theme) Underline

func (t *Theme) Underline(text string) string

Underline mirrors chalk.underline.

type ThemeBg

type ThemeBg = string

ThemeBg names a background color token (pi: ThemeBg union). Alias for the same reason as ThemeColor.

const (
	BgSelectedBg      ThemeBg = "selectedBg"
	BgSearchMatchBg   ThemeBg = "searchMatchBg"
	BgUserMessageBg   ThemeBg = "userMessageBg"
	BgCustomMessageBg ThemeBg = "customMessageBg"
	BgToolPendingBg   ThemeBg = "toolPendingBg"
	BgToolSuccessBg   ThemeBg = "toolSuccessBg"
	BgToolErrorBg     ThemeBg = "toolErrorBg"
)

type ThemeColor

type ThemeColor = string

ThemeColor names a foreground color token (pi: ThemeColor union). Declared deviation: a string alias (not a named type) so that *Theme structurally satisfies core.UITheme — package core cannot import this package (theme → core for SourceInfo), so renderer signatures in core accept the structural interface.

const (
	ColorAccent             ThemeColor = "accent"
	ColorBorder             ThemeColor = "border"
	ColorBorderAccent       ThemeColor = "borderAccent"
	ColorBorderMuted        ThemeColor = "borderMuted"
	ColorSuccess            ThemeColor = "success"
	ColorError              ThemeColor = "error"
	ColorWarning            ThemeColor = "warning"
	ColorMuted              ThemeColor = "muted"
	ColorDim                ThemeColor = "dim"
	ColorText               ThemeColor = "text"
	ColorThinkingText       ThemeColor = "thinkingText"
	ColorSearchMatchText    ThemeColor = "searchMatchText"
	ColorUserMessageText    ThemeColor = "userMessageText"
	ColorCustomMessageText  ThemeColor = "customMessageText"
	ColorCustomMessageLabel ThemeColor = "customMessageLabel"
	ColorToolTitle          ThemeColor = "toolTitle"
	ColorToolOutput         ThemeColor = "toolOutput"
	ColorMdHeading          ThemeColor = "mdHeading"
	ColorMdLink             ThemeColor = "mdLink"
	ColorMdLinkUrl          ThemeColor = "mdLinkUrl"
	ColorMdCode             ThemeColor = "mdCode"
	ColorMdCodeBlock        ThemeColor = "mdCodeBlock"
	ColorMdCodeBlockBorder  ThemeColor = "mdCodeBlockBorder"
	ColorMdQuote            ThemeColor = "mdQuote"
	ColorMdQuoteBorder      ThemeColor = "mdQuoteBorder"
	ColorMdHr               ThemeColor = "mdHr"
	ColorMdListBullet       ThemeColor = "mdListBullet"
	ColorToolDiffAdded      ThemeColor = "toolDiffAdded"
	ColorToolDiffRemoved    ThemeColor = "toolDiffRemoved"
	ColorToolDiffContext    ThemeColor = "toolDiffContext"
	ColorSyntaxComment      ThemeColor = "syntaxComment"
	ColorSyntaxKeyword      ThemeColor = "syntaxKeyword"
	ColorSyntaxFunction     ThemeColor = "syntaxFunction"
	ColorSyntaxVariable     ThemeColor = "syntaxVariable"
	ColorSyntaxString       ThemeColor = "syntaxString"
	ColorSyntaxNumber       ThemeColor = "syntaxNumber"
	ColorSyntaxType         ThemeColor = "syntaxType"
	ColorSyntaxOperator     ThemeColor = "syntaxOperator"
	ColorSyntaxPunctuation  ThemeColor = "syntaxPunctuation"
	ColorThinkingOff        ThemeColor = "thinkingOff"
	ColorThinkingMinimal    ThemeColor = "thinkingMinimal"
	ColorThinkingLow        ThemeColor = "thinkingLow"
	ColorThinkingMedium     ThemeColor = "thinkingMedium"
	ColorThinkingHigh       ThemeColor = "thinkingHigh"
	ColorThinkingXhigh      ThemeColor = "thinkingXhigh"
	ColorThinkingMax        ThemeColor = "thinkingMax"
	ColorBashMode           ThemeColor = "bashMode"
	// Scrollbar colors are foreground tokens as of v0.85.1 (pi: moved
	// scrollbarThumb from ThemeBg to ThemeColor and added scrollbarTrack; both
	// optional, falling back to muted/text).
	ColorScrollbarTrack ThemeColor = "scrollbarTrack"
	ColorScrollbarThumb ThemeColor = "scrollbarThumb"
	// ImagePlaceholder is a pig-only optional token (pi has no equivalent):
	// colors the [Image N] clipboard-paste placeholder in the editor
	// (docs/feat/CLIPBOARD-IMAGE-PLACEHOLDER.md). Optional, falling back to
	// accent for themes that do not define it.
	ColorImagePlaceholder ThemeColor = "imagePlaceholder"
)

type ThemeControllerTUI

type ThemeControllerTUI interface {
	Invalidate()
	RequestRender(force bool)
	SetTerminalColorSchemeNotifications(enabled bool)
	OnTerminalColorSchemeChange(listener func(scheme tui.TerminalColorScheme)) func()
	QueryTerminalColors(timeoutMs int, onLateReply func(colors tui.TerminalColors)) tui.TerminalColors
}

ThemeControllerTUI is the TUI surface consumed by the controller (pi: TUI used via invalidate/requestRender/setTerminalColorSchemeNotifications/ onTerminalColorSchemeChange/queryTerminalColors).

type ThemeExportColors

type ThemeExportColors struct {
	PageBg string
	CardBg string
	InfoBg string
}

ThemeExportColors is pi's { pageBg?, cardBg?, infoBg? } ("" = unset).

func GetThemeExportColors

func GetThemeExportColors(themeName string) ThemeExportColors

GetThemeExportColors reads the explicit export colors from a theme's export section, resolving variable references (pi: getThemeExportColors). Unset colors are "" (pi: undefined); load failures yield the zero struct (pi: {}).

type ThemeExportJson

type ThemeExportJson struct {
	PageBg ColorValue `json:"pageBg,omitempty"`
	CardBg ColorValue `json:"cardBg,omitempty"`
	InfoBg ColorValue `json:"infoBg,omitempty"`
}

ThemeExportJson is the optional export section (pi: export).

type ThemeInfo

type ThemeInfo struct {
	Name string
	Path string // "" = none (pi: path?: string)
}

ThemeInfo is pi's ThemeInfo.

func GetAvailableThemesWithPaths

func GetAvailableThemesWithPaths() []ThemeInfo

type ThemeJson

type ThemeJson struct {
	Schema     string                `json:"$schema,omitempty"`
	Name       string                `json:"name"`
	Appearance TerminalTheme         `json:"appearance,omitempty"`
	Vars       map[string]ColorValue `json:"vars,omitempty"`
	Colors     map[string]ColorValue `json:"colors"`
	Export     *ThemeExportJson      `json:"export,omitempty"`
}

ThemeJson mirrors the theme JSON schema (pi: ThemeJsonSchema/ThemeJson).

func ValidateThemeJson

func ValidateThemeJson(label string, parsed any) (*ThemeJson, error)

ValidateThemeJson hand-validates the theme schema (pi: validateThemeJson in theme-json.ts; pig hand-writes the TypeBox shape). Missing required colors keep pi's diagnostic formatting; the theme name may not contain "/".

type ThemeJsonValidator

type ThemeJsonValidator = func(label string, json any) (*ThemeJson, error)

ThemeJsonValidator validates one theme document (pi: ThemeJsonValidator).

type ThemeOptions

type ThemeOptions struct {
	Name       string
	SourcePath string
	SourceInfo *utils.SourceInfo
	// Appearance is the background the theme is designed for, declared in the
	// theme JSON (pi: options.appearance). "" = detect from the colors.
	Appearance TerminalTheme
	// Dim lists foreground tokens rendered faint (SGR 2) on top of their
	// color (pi: options.dim).
	Dim []ThemeColor
}

ThemeOptions carries the constructor's optional fields (pi: options object; "" / nil = undefined).

type ThemeResult

type ThemeResult struct {
	Success bool
	Error   string
}

ThemeResult is pi's ThemeResult = { success: boolean; error?: string }.

type ThemeSettingsManager

type ThemeSettingsManager interface {
	// GetThemeSetting is pi's settingsManager.getThemeSetting().
	GetThemeSetting() (string, bool)
	// SetTheme is pi's settingsManager.setTheme().
	SetTheme(theme string)
	// Flush is pi's settingsManager.flush().
	Flush()
}

ThemeSettingsManager is the SettingsManager surface the controller consumes (pi: SettingsManager). Declared deviation: package theme cannot import core (core → core/tools → theme would cycle); *core.SettingsManager satisfies this interface structurally.

type ThemeStyle added in v1.0.0

type ThemeStyle struct {
	tui.TextAttributes
	// Fg: nil (terminal default untouched), ThemeColor (string), or tui.Color.
	Fg any
	// Bg: nil, ThemeBg (string), or tui.Color.
	Bg any
}

ThemeStyle is a style request for Theme.Style: fg is a ThemeColor token or a concrete color, bg is a ThemeBg token or a concrete color (pi: ThemeStyle; the any fields hold tui.Color for concrete colors).

type ThemeToken added in v1.0.0

type ThemeToken = string

ThemeToken is ThemeColor | ThemeBg (pi: ThemeToken union).

Jump to

Keyboard shortcuts

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