Documentation
¶
Overview ¶
Package termimage renders images to terminals.
Backends cover the modern image protocols — kitty graphics (kitty, Ghostty, Konsole), iTerm2 inline images (iTerm2, WezTerm), and sixel (Windows Terminal, foot, mlterm, xterm) — plus ANSI tiers that work everywhere: truecolor half blocks and a plain ASCII ramp.
Everything is written in-repo on the standard library alone: no cgo, no new module dependencies, no copied protocol code. Decoding uses image/png, image/jpeg, and image/gif; base64 and PNG encoding are stdlib; scaling, adaptive palette quantization, and optional dithering are ours and deterministic, so protocol output is golden-testable.
Backend selection is automatic by default: environment signals pick kitty and iTerm2 terminals, a DA1 probe asks about sixel on real consoles, and the ANSI tiers catch everything else. An explicit Backend always wins. A disabled Scheme degrades Auto to ASCII, so piped output stays plain text.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Backend ¶
type Backend int
Backend selects an image protocol or ANSI tier.
const ( // Auto detects the best backend for the current terminal. Auto Backend = iota // Kitty is the kitty graphics protocol. Kitty // ITerm2 is the iTerm2 OSC 1337 inline image protocol. ITerm2 // Sixel is DEC sixel (DCS). Sixel // HalfBlock paints two pixel rows per cell with upper half blocks. HalfBlock // ASCII paints luminance through a character ramp. ASCII )
Backends from richest to plainest.
type Options ¶
type Options struct {
// Backend forces a protocol; zero Auto detects from the terminal.
Backend Backend
// Width caps the render in cells; zero uses the terminal width.
Width int
// Height caps the render in cells; zero keeps the image aspect.
Height int
// Dither enables Floyd-Steinberg error diffusion wherever a backend
// quantizes: the sixel adaptive palette, 256-color half blocks, and
// the ascii ramp. Exact-pixel paths (kitty, iterm2, truecolor half
// blocks) send full color and are unaffected.
Dither bool
// Background flattens transparency when it has alpha: every backend
// blends the image over this color. The zero value keeps
// transparency instead — kitty and iterm2 send native alpha, sixel
// leaves those pixels unpainted, and half blocks and ascii render
// them as blanks, all letting the terminal background show through.
Background color.RGBA
// CellWidth and CellHeight override the per-cell pixel estimate
// used for sizing; zero queries the terminal.
CellWidth int
CellHeight int
// ImageID is the kitty graphics image id. Zero sends every render
// as a fresh anonymous image, so sequential renders coexist; a
// non-zero id makes a retransmit replace earlier renders of that
// id in place, which suits redrawing a widget or an animation.
ImageID uint32
}
Options tunes a render.