filepreview

package
v0.0.0-...-5d475a2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPixelsPerColumn = 10 // approximate pixels per terminal column
	DefaultPixelsPerRow    = 20 // approximate pixels per terminal row
)

Terminal cell to pixel conversion constants These approximate the pixel dimensions of terminal cells

Variables

This section is empty.

Functions

func ClearKittyImages

func ClearKittyImages() string

ClearKittyImages clears all Kitty protocol images from the terminal

func ConvertImageToANSI

func ConvertImageToANSI(img image.Image, defaultBGColor color.Color) string

ConvertImageToANSI converts an image to ANSI escape codes with proper aspect ratio

Types

type CachedPreview

type CachedPreview struct {
	Preview    string
	Timestamp  time.Time
	Renderer   ImageRenderer
	Dimensions string // "width,height,bgColor,sideAreaWidth"
}

CachedPreview represents a cached image preview

type ImagePreviewCache

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

ImagePreviewCache stores cached image previews

func NewImagePreviewCache

func NewImagePreviewCache(maxEntries int, expiration time.Duration) *ImagePreviewCache

NewImagePreviewCache creates a new image preview cache

func (*ImagePreviewCache) Get

func (c *ImagePreviewCache) Get(path, dimensions string, renderer ImageRenderer) (string, bool)

Get retrieves a cached preview if available

func (*ImagePreviewCache) Set

func (c *ImagePreviewCache) Set(path, dimensions, preview string, renderer ImageRenderer)

Set stores a preview in the cache

type ImagePreviewer

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

ImagePreviewer encapsulates image preview functionality with caching

func NewImagePreviewer

func NewImagePreviewer() *ImagePreviewer

NewImagePreviewer creates a new ImagePreviewer with default cache settings

func NewImagePreviewerWithConfig

func NewImagePreviewerWithConfig(maxEntries int, expiration time.Duration) *ImagePreviewer

NewImagePreviewerWithConfig creates a new ImagePreviewer with custom cache configuration

func (*ImagePreviewer) ANSIRenderer

func (p *ImagePreviewer) ANSIRenderer(img image.Image, defaultBGColor string,
	maxWidth int, maxHeight int) (string, error)

Convert image to ansi

func (*ImagePreviewer) ClearKittyImages

func (p *ImagePreviewer) ClearKittyImages() string

ClearKittyImages clears all Kitty protocol images from the terminal

func (*ImagePreviewer) ImagePreview

func (p *ImagePreviewer) ImagePreview(path string, maxWidth int, maxHeight int,
	defaultBGColor string, sideAreaWidth int) (string, error)

ImagePreview generates a preview of an image file

func (*ImagePreviewer) ImagePreviewWithRenderer

func (p *ImagePreviewer) ImagePreviewWithRenderer(path string, maxWidth int, maxHeight int,
	defaultBGColor string, renderer ImageRenderer, sideAreaWidth int) (string, error)

ImagePreviewWithRenderer generates an image preview using the specified renderer

func (*ImagePreviewer) InitTerminalCapabilities

func (p *ImagePreviewer) InitTerminalCapabilities()

InitTerminalCapabilities initializes terminal capabilities for the ImagePreviewer

func (*ImagePreviewer) IsKittyCapable

func (p *ImagePreviewer) IsKittyCapable() bool

IsKittyCapable checks if the terminal supports Kitty graphics protocol

type ImageRenderer

type ImageRenderer int
const (
	RendererANSI ImageRenderer = iota
	RendererKitty
)

type TerminalCapabilities

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

TerminalCapabilities encapsulates terminal capability detection

func NewTerminalCapabilities

func NewTerminalCapabilities() *TerminalCapabilities

NewTerminalCapabilities creates a new TerminalCapabilities instance

func (*TerminalCapabilities) GetTerminalCellSize

func (tc *TerminalCapabilities) GetTerminalCellSize() TerminalCellSize

GetTerminalCellSize returns the current terminal cell size If detection hasn't been initialized, it performs detection first

func (*TerminalCapabilities) InitTerminalCapabilities

func (tc *TerminalCapabilities) InitTerminalCapabilities()

InitTerminalCapabilities initializes all terminal capabilities detection including cell size and Kitty Graphics Protocol support This should be called early in the application startup

type TerminalCellSize

type TerminalCellSize struct {
	PixelsPerColumn int
	PixelsPerRow    int
}

TerminalCellSize represents the pixel dimensions of terminal cells

Jump to

Keyboard shortcuts

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