Documentation
¶
Overview ¶
Package render handles terminal color output for wondertone Tones.
It detects the terminal's color capability and outputs the best possible ANSI escape sequence — TrueColor, 256-color, or 16-color. Downsampling is perceptual (OKLab ΔE nearest-neighbor), not RGB distance.
Import as "render":
import render "github.com/leraniode/wondertone/render" profile := render.Detect() fmt.Print(render.FG(myTone, profile), "Hello, wondertone", render.Reset)
Index ¶
- Constants
- func BG(t tone.Tone, p Profile) string
- func Colorize(t tone.Tone, p Profile, text string) string
- func ColorizeOnBG(fg, bg tone.Tone, p Profile, text string) string
- func FG(t tone.Tone, p Profile) string
- func LipglossColor(t tone.Tone, p Profile) string
- func LipglossColorHex(t tone.Tone) string
- func Swatch(t tone.Tone, p Profile, width int) string
- type Profile
Constants ¶
const ( Reset = "\x1b[0m" Bold = "\x1b[1m" Dim = "\x1b[2m" Italic = "\x1b[3m" Underline = "\x1b[4m" )
ANSI escape codes
Variables ¶
This section is empty.
Functions ¶
func ColorizeOnBG ¶
ColorizeOnBG wraps text with FG and BG colors and a reset.
func FG ¶
FG returns the ANSI escape sequence to set the foreground to the given Tone. The sequence is adapted to the terminal Profile.
func LipglossColor ¶
LipglossColor converts a Tone to a lipgloss-compatible color value string.
Usage with lipgloss (import lipgloss separately):
import "github.com/charmbracelet/lipgloss"
style := lipgloss.NewStyle().
Foreground(lipgloss.Color(render.LipglossColor(myTone, profile)))
Returns a string that lipgloss.Color() accepts:
- TrueColor: "#rrggbb"
- ANSI256: "42" (the 256-color index as a string)
- ANSI16: "2" (the 16-color index as a string)
- NoColor: "" (lipgloss will render unstyled)
func LipglossColorHex ¶
LipglossColorHex always returns the hex value regardless of profile. Use this when lipgloss itself handles profile detection (e.g. via ColorProfile adapter).
Types ¶
type Profile ¶
type Profile int
Profile represents the terminal's color capability.
const ( // TrueColor supports 24-bit RGB — the full wondertone experience. TrueColor Profile = iota // ANSI256 supports 256 colors — perceptual nearest-neighbor downsampling. ANSI256 // ANSI16 supports the 16 standard ANSI colors — best-effort perceptual map. ANSI16 // NoColor disables all color output. NoColor )
func Detect ¶
func Detect() Profile
Detect reads environment variables to determine the terminal's color profile. Checks (in order): NO_COLOR, COLORTERM, TERM, TERM_PROGRAM, CI.
For guaranteed detection in production, pair with charmbracelet/colorprofile.