Documentation
¶
Index ¶
- Constants
- func CleanupSequence(env Environment) string
- func ClearCache()
- func Debugf(env Environment, format string, args ...any)
- func KittyDeleteImageSequence(imageIDs ...uint32) string
- func KittyDeleteVisibleSequence() string
- func KittyPlaceSequence(imageID uint32, cols, rows int) string
- func KittyPlaceholderGrid(imageID uint32, cols, rows int) string
- type Environment
- type Mode
- type Protocol
- type Request
- type Result
- type Strategy
Constants ¶
const ( DefaultMaxCols = 80 DefaultMaxRows = 40 DefaultCellWidthPx = 10 DefaultCellHeightPx = 20 )
Variables ¶
This section is empty.
Functions ¶
func CleanupSequence ¶
func CleanupSequence(env Environment) string
CleanupSequence returns terminal image cleanup bytes appropriate for env. It is intentionally conservative: only Kitty-style graphics currently need an explicit cleanup command for alt-screen teardown.
func Debugf ¶ added in v0.0.233
func Debugf(env Environment, format string, args ...any)
func KittyDeleteImageSequence ¶ added in v0.0.233
KittyDeleteImageSequence returns Kitty graphics commands that delete the specific image ids owned by this process. Prefer this to global cleanup when the ids are known, so unrelated Kitty graphics are not disturbed.
func KittyDeleteVisibleSequence ¶
func KittyDeleteVisibleSequence() string
KittyDeleteVisibleSequence returns a Kitty graphics command that deletes all image placements currently visible on the terminal screen and asks the terminal to free associated image data where possible. It is useful when leaving an alternate-screen UI so Kitty/Ghostty placements do not bleed into the restored main screen.
func KittyPlaceSequence ¶ added in v0.0.233
KittyPlaceSequence creates or updates a virtual Unicode-placeholder placement for an already-transmitted Kitty image id.
func KittyPlaceholderGrid ¶ added in v0.0.233
KittyPlaceholderGrid returns the Unicode placeholder grid for imageID.
Types ¶
type Environment ¶
type Environment struct {
Term string
TermProgram string
LCTerminal string
KittyWindowID string
ColorTerm string
Tmux string
Screen string
ForcedProtocol string
Debug bool
DebugFile string
}
Environment captures terminal-related environment used for deterministic protocol selection. DefaultEnvironment reads these fields from os.Environ.
func DefaultEnvironment ¶
func DefaultEnvironment() Environment
DefaultEnvironment returns terminal-image relevant environment variables.
type Mode ¶
type Mode string
Mode identifies the output surface the rendered image is destined for.
const ( // ModeViewport is Bubble Tea viewport content. Results must be safe to line // clip and redraw; raw image upload escapes are returned separately in Upload. ModeViewport Mode = "viewport" // ModeScrollback is inline/scrollback terminal output. One-shot escape based // renderers are acceptable here. ModeScrollback Mode = "scrollback" // ModeOneShot is direct terminal output outside a redrawable viewport. ModeOneShot Mode = "oneshot" )
type Protocol ¶
type Protocol string
Protocol identifies a terminal image rendering protocol/strategy.
type Request ¶
type Request struct {
Path string
MaxCols int
MaxRows int
Mode Mode
Protocol Protocol
// Background is used by text-based renderers when compositing transparent
// pixels. If nil or transparent, a dark terminal-style fallback is used.
Background color.Color
// AllowEscapeUploads is reserved for callers that want to explicitly document
// whether they can emit Upload out-of-band. Protocol selection currently uses
// Protocol=ansi/none for text-only operation.
AllowEscapeUploads bool
// CellWidthPx/CellHeightPx optionally override terminal cell pixel size.
// When zero, the renderer tries to detect the size and falls back to 10x20.
CellWidthPx int
CellHeightPx int
// SliceStartRow/SliceRows request a vertical cell slice of the scaled image.
// This is used by redrawable viewport integrations that need to display only
// the visible portion of an image. Zero SliceRows means render the full image.
SliceStartRow int
SliceRows int
}
Request describes an image render request.
type Result ¶
type Result struct {
Protocol Protocol
// Upload contains terminal control bytes that must be emitted directly to the
// terminal, outside any line-wrapping/slicing viewport content.
Upload string
// Place contains terminal control bytes that create/update the visible image
// placement after Upload has completed. It is separate for redrawable viewport
// integrations that need to gate placeholders until both transmit and
// placement commands have been flushed.
Place string
// Display is safe for the requested output surface. For Kitty viewport mode it
// is only the Unicode placeholder grid. For ANSI it is ordinary ANSI text.
Display string
// Full is a one-shot convenience string equal to Upload + Place + Display.
Full string
WidthCells int
HeightCells int
ImageID uint32
PlacementID uint32
TextFallback string
CacheKey string
Warnings []string
}
Result is the normalized output shape returned by all rendering strategies.
func KittyPlacementForPath ¶ added in v0.0.233
KittyPlacementForPath calculates viewport cell dimensions for path and returns a placement-only Kitty result for an already-transmitted image id. It decodes image metadata but does not re-encode or retransmit PNG bytes.
func RenderWithEnvironment ¶
func RenderWithEnvironment(req Request, env Environment) (Result, error)
RenderWithEnvironment renders an image using an explicit environment. It is primarily useful for deterministic tests and debugging.