Help us shape the future of Go! Take the 2026 Go Developer Survey

terminalimage

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package terminalimage writes native images, image fonts, or color-block previews.

Index

Constants

This section is empty.

Variables

View Source
var ErrSavedImageChanged = errors.New("saved image contents changed before preview")

ErrSavedImageChanged means the preview bytes differ from the completed save.

Functions

func CellSize added in v1.28.0

func CellSize(fd uintptr) (width, height int)

CellSize reads the text cell dimensions from existing window metadata without sending terminal queries or consuming input. Only their ratio is significant. When dimensions are missing or ambiguous, use the conventional 1-by-2 estimate.

func DecodePreview added in v1.28.0

func DecodePreview(ctx context.Context, source io.Reader) (image.Image, error)

DecodePreview decodes temporary image bytes using the same optional-preview limits as saved images. It never writes a file or limits the API response.

func FontPreviewColumns added in v1.28.0

func FontPreviewColumns(bounds image.Rectangle, columns, rows int) int

FontPreviewColumns also fits the gallery's immutable row allocation. Gallery placements assume cells twice as tall as wide, regardless of the font; the bitmap itself still preserves proportions within those allocated cells.

func FontSupported

func FontSupported() bool

FontSupported identifies a local Apple Terminal session. Font registration and tab control must never target a remote shell or a terminal multiplexer.

func ReadSaved

func ReadSaved(ctx context.Context, path string) (image.Image, error)

ReadSaved decodes an optional preview. These limits protect terminal rendering; they never limit the API response or change the original saved image.

func ReadSavedMatching

func ReadSavedMatching(ctx context.Context, path string, expected [sha256.Size]byte) (image.Image, error)

ReadSavedMatching previews only the response bytes recorded by a prior save. Both identity checks and decoding apply to the same bounded snapshot, so a replaced path or a rewritten open file cannot substitute another image.

func Write

func Write(ctx context.Context, w io.Writer, img image.Image, protocol string, columns int) error

Write displays img at the requested width in terminal cells, preserving its aspect ratio. The caller selects the protocol and supplies a terminal writer.

func WriteProgress added in v1.28.0

func WriteProgress(ctx context.Context, w io.Writer, img image.Image, protocol string, columns int) error

WriteProgress uses the same renderer as a final image, while leaving capacity for one final font preview. Sharp progress keeps immutable private cache files because changing their glyphs would change earlier terminal scrollback.

Types

type FontError

type FontError struct{ Err error }

FontError means preparing a sharp preview failed before any image characters were written, and any attempted rollback succeeded. Other failures must not silently fall back or continue past uncertain terminal state.

func (*FontError) Error

func (e *FontError) Error() string

func (*FontError) Unwrap

func (e *FontError) Unwrap() error

Jump to

Keyboard shortcuts

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