picture

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultKittyID = 43

Variables

This section is empty.

Functions

func IsPictureMsg

func IsPictureMsg(msg tea.Msg) bool

IsPictureMsg reports whether msg is a picture-owned async update.

Types

type Config

type Config struct {
	KittyID    int         // default 43
	Background color.Color // default color.Transparent (no compositing)
}

Config configures a Model at construction.

type KittyFrameMsg

type KittyFrameMsg struct {
	ID   int
	Seq  uint64
	APC  string
	Grid string
	// contains filtered or unexported fields
}

KittyFrameMsg carries the result of building a Kitty APC payload + grid for a specific generation of the Model. Update() ignores frames whose modelID (a per-Model atomic counter, unforgeable from outside the package) does not match the receiving Model's, or whose Seq does not match the Model's current seq (image/size/mode changed since dispatch). The modelID check is what prevents cross-talk when multiple Models share a tea.Program — every msg is forwarded to every Model — even if they happen to share a Kitty image ID.

type Model

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

Model renders an image.Image as half-blocks or Kitty graphics inside a Bubble Tea program. The Model has no notion of where images come from; callers feed it via SetImage. For URL-driven fetching, see pictureurl.

func New

func New() Model

New returns a Model with default Config.

func NewWithConfig

func NewWithConfig(cfg Config) Model

NewWithConfig returns a Model with the supplied Config. Zero/nil fields are filled with defaults.

func (*Model) Mode

func (m *Model) Mode() PictureMode

Mode returns the current rendering mode.

func (*Model) SetImage

func (m *Model) SetImage(img image.Image) tea.Cmd

SetImage sets the image to render. Pass nil to clear. Returns a tea.Cmd if rendering needs to be scheduled (Kitty mode), or a cleanup Cmd if Kitty was previously placed and is now being cleared, or nil otherwise.

In Kitty mode with a non-nil new image, the previous placeholder grid is preserved until the new KittyFrameMsg arrives. The grid is a pure function of (cols, rows, kittyID) — byte-identical between renders when those are stable — and the previously-resident image at kittyID stays visible until the new APC overwrites it. Clearing the grid synchronously would create a visible blank window during animation.

func (*Model) SetSize

func (m *Model) SetSize(cols, rows int) tea.Cmd

SetSize updates the rendering dimensions in terminal cells. Returns a render Cmd in Kitty mode (re-encode for the new size) or nil otherwise.

func (*Model) String

func (m *Model) String() string

String returns the rendered image content as a plain string.

func (*Model) Toggle

func (m *Model) Toggle() tea.Cmd

Toggle switches between Glyph and Kitty modes. When toggling away from Kitty after an image was placed, returns a Cmd that emits the Kitty delete sequence; otherwise returns the Cmd to render in the new mode (or nil).

func (*Model) Update

func (m *Model) Update(msg tea.Msg) tea.Cmd

Update processes the picture component's own messages. Forward every tea.Msg to it; unknown messages are ignored and return nil.

func (*Model) View

func (m *Model) View() tea.View

View returns the rendered image as a tea.View, or an empty view if there is no image, no size, or (in Kitty mode) the encoded frame is not yet ready. The Model never renders user-facing loading or error text; layers above (e.g. pictureurl) own that.

type PictureMode

type PictureMode int8

PictureMode selects how images are rendered.

const (
	PictureGlyph PictureMode = iota // Universal half-block ANSI
	PictureKitty                    // High-res Kitty graphics protocol
)

Directories

Path Synopsis
Package chartpicture is a go-analyze/charts source for picture.Model.
Package chartpicture is a go-analyze/charts source for picture.Model.
Package pictureurl is a URL-driven layer on top of picture.Model.
Package pictureurl is a URL-driven layer on top of picture.Model.

Jump to

Keyboard shortcuts

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