image

package
v0.74.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package image handles terminal image preview rendering using the Halfblocks protocol, with LRU caching and graphics protocol detection.

Index

Constants

View Source
const (
	MaxImageSize    = 10 * 1024 * 1024 // 10MB
	MaxCacheEntries = 20
)

Variables

This section is empty.

Functions

func IsImageFile

func IsImageFile(path string) bool

IsImageFile checks if path has a supported image extension

func SupportedTerminals

func SupportedTerminals() string

SupportedTerminals returns a string about image preview support

Types

type Protocol

type Protocol int

Protocol represents terminal graphics capability

const (
	ProtocolNone Protocol = iota
	ProtocolKitty
	ProtocolITerm2
	ProtocolSixel
)

func (Protocol) String

func (p Protocol) String() string

String returns human-readable protocol name

type RenderResult

type RenderResult struct {
	Content    string // ANSI escape sequences for image
	IsFallback bool   // True if showing text message
	Width      int
	Height     int
}

RenderResult contains rendered output or fallback

type Renderer

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

Renderer handles image preview rendering

func New

func New() *Renderer

New creates a renderer and detects protocol

func (*Renderer) CacheStats

func (r *Renderer) CacheStats() (entries int, maxEntries int)

CacheStats returns cache statistics for debugging

func (*Renderer) ClearCache

func (r *Renderer) ClearCache()

ClearCache clears the render cache

func (*Renderer) InvalidatePath

func (r *Renderer) InvalidatePath(path string)

InvalidatePath removes cached entries for a specific path

func (*Renderer) Protocol

func (r *Renderer) Protocol() Protocol

Protocol returns detected protocol

func (*Renderer) Render

func (r *Renderer) Render(path string, maxW, maxH int) (*RenderResult, error)

Render renders an image to terminal graphics using Halfblocks protocol. Halfblocks uses Unicode block characters (▀▄█) with ANSI colors, which integrates properly with TUI frameworks like Bubble Tea. Native protocols (Kitty, iTerm2, Sixel) bypass TUI rendering and write directly to terminal.

Jump to

Keyboard shortcuts

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