Documentation
¶
Overview ¶
Package theme — filter.go: byte-level ANSI SGR rewriter.
Kept dependency-free (no regexp) so the per-write overhead stays tiny — the filter sits on the hot path of every Printf in the codebase.
Package theme — install.go: optional os.Stdout / os.Stderr interception that pipes every write through Filter for the active mode. Skipped entirely for ModeBright so the default code path stays a true zero-cost passthrough.
Package theme resolves the active terminal color palette and installs an ANSI rewrite filter on stdout / stderr so every existing Print / Printf call adapts to the user's --theme choice without per-site changes.
Three modes:
- bright (default): passthrough — the bright + bold ANSI palette baked into constants.Color* is what the user sees.
- standard: downgrade bright codes to plain 3X codes (the pre-v5.13 look) for users on light themes or older terminals where bright-bold is too loud.
- monochrome / mono: strip every SGR escape so output stays readable when piped into tools that don't grok ANSI (diff, less without -R, log scrapers).
Resolution order (first wins):
- `--theme=<mode>` / `--theme <mode>` on the command line (stripped from os.Args by cmd.stripThemeFlag before subcommand dispatch).
- GITMAP_THEME env var (also exported by the flag stripper so subprocesses inherit the choice).
- constants.ThemeDefault.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Drain ¶
func Drain()
Drain closes every installed pipe writer and waits for the matching forwarder goroutine to flush its buffered bytes to the underlying destination fd. MUST be called before os.Exit when output integrity matters (e.g. cliexit.Fail) — otherwise the last failure message can vanish on Windows.
func Filter ¶
Filter applies the active mode's transformation to p. Bright mode is a passthrough; other modes scan for SGR escape sequences (ESC `[` ... `m`) and rewrite or drop them.
func Install ¶
func Install()
Install resolves the active mode from the environment and, if it is not ModeBright, replaces os.Stdout and os.Stderr with pipe-backed writers whose reader-side goroutines apply Filter before forwarding bytes to the original fds. Safe to call multiple times — runs at most once per process.
func IsStdoutTTY ¶
func IsStdoutTTY() bool
IsStdoutTTY reports whether the *original* stdout (before any theme pipe interception) is a real terminal. Callers in gitmap/render gate ANSI pretty-rendering on this so the monochrome / standard pipe wrappers don't break TTY detection.
func IsValidLabel ¶
IsValidLabel reports whether label names a known theme. Used by the flag stripper to reject typos with a clear error instead of silently falling back.
Types ¶
type Mode ¶
type Mode int
Mode is the resolved palette selection.
func Active ¶
func Active() Mode
Active returns the mode chosen at Install time. Defaults to ModeBright when Install has not yet been called.
func Parse ¶
Parse maps a user-supplied label to a Mode. Unknown labels (and the empty string) fall back to ModeBright so a typo never crashes a CLI run — they just render in the default palette.