image

package
v1.113.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package image prepares and renders images for terminal display.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KittySequence

func KittySequence(pngData []byte, cols, rows int) string

KittySequence encodes PNG data as a kitty graphics escape sequence.

func Render

func Render(img Inline, width int) []string

Render returns a label, kitty image sequence, and the rows reserved by it.

func RenderMarkers

func RenderMarkers(img Inline, width int) []string

RenderMarkers renders a compact marker on every occupied row. The normal TUI resolves these after viewport clipping, which lets it crop images that are partially scrolled off-screen without copying PNG data into every row.

func SetRenderingEnabled

func SetRenderingEnabled(enabled bool)

SetRenderingEnabled controls whether the full-screen TUI reserves image rows.

func SupportsKittyGraphics

func SupportsKittyGraphics(in, out *os.File) bool

SupportsKittyGraphics probes a terminal for Kitty graphics support. It must run before the TUI takes ownership of the terminal input stream.

Types

type Inline

type Inline struct {
	Name    string
	MIME    string
	PNGData []byte
	Width   int
	Height  int
}

Inline is a PNG image prepared for inline kitty-protocol rendering.

func FromBase64

func FromBase64(name, mimeType, encoded string) (Inline, bool)

FromBase64 decodes and normalizes one base64-encoded image.

func FromBytes

func FromBytes(name, mimeType string, data []byte) (Inline, bool)

FromBytes normalizes encoded image bytes for terminal rendering.

func FromToolResult

func FromToolResult(result *tools.ToolCallResult) []Inline

FromToolResult extracts displayable images from a tool result.

func LoadMarkdownReference

func LoadMarkdownReference(ctx context.Context, ref MarkdownReference) (Inline, bool)

LoadMarkdownReference resolves a data URI, local path, or public HTTP URL.

type MarkdownReference

type MarkdownReference struct {
	Alt    string
	Source string
	Start  int
	End    int
}

MarkdownReference is an image embedded with Markdown's ![alt](source) syntax.

func MarkdownReferences

func MarkdownReferences(markdown string) []MarkdownReference

MarkdownReferences extracts image references in document order.

type Writer

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

Writer adds kitty graphics after Bubble Tea has rendered its text cell buffer. Bubble Tea intentionally consumes APC sequences while parsing view content, so images must be overlaid on the completed frame instead.

func NewWriter

func NewWriter(out io.Writer) *Writer

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) Fd

func (w *Writer) Fd() uintptr

Fd, Read, and Close preserve the terminal file interface when Writer wraps stdout. Bubble Tea uses that interface to detect the output TTY.

func (*Writer) Invalidate

func (w *Writer) Invalidate()

Invalidate forces image data and placements to be rebuilt after the terminal clears graphics state, such as during a resize or terminal restore.

func (*Writer) Read

func (w *Writer) Read(p []byte) (int, error)

func (*Writer) RenderingEnabled

func (w *Writer) RenderingEnabled() bool

RenderingEnabled reports whether both the user setting and terminal support allow images.

func (*Writer) SetContent

func (w *Writer) SetContent(content string) string

func (*Writer) SetEnabled

func (w *Writer) SetEnabled(enabled bool)

SetEnabled controls whether image markers become terminal overlays.

func (*Writer) SetSupported

func (w *Writer) SetSupported(supported bool)

SetSupported records whether the terminal answered the Kitty graphics probe.

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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