kittyimg

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 30 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MaxRows = 4

MaxRows is the maximum number of terminal rows an image may span.

Variables

View Source
var (
	BaseImageDirectory = filepath.Join(xdg.DataHome, "chatuino")
)
View Source
var ErrUnsupportedAnimatedFormat = errors.New("emote is animated but in non supported format")

Functions

func PlaceholderID added in v1.5.0

func PlaceholderID(text string) (int32, bool)

PlaceholderID returns the image ID encoded in the first placeholder of text.

func PlaceholderRowsAbove added in v1.4.0

func PlaceholderRowsAbove(line string, rows int) []string

PlaceholderRowsAbove returns the rows-1 terminal lines that must be rendered above line, so multi-row images in line (which contains their bottom row) are displayed in full. Every placeholder cell in line is repeated at the same column with the matching row diacritic; all other cells become spaces. Returns nil if rows <= 1 or line contains no placeholders.

Types

type CellSize added in v1.5.0

type CellSize struct {
	Width, Height float32
}

CellSize is the terminal cell size in pixels. Kept together because every image geometry calculation needs both dimensions.

type DecodedImage

type DecodedImage struct {
	ID     int32               `json:"-"`
	Cols   int                 `json:"cols"`
	Images []DecodedImageFrame `json:"images"`

	// Rows is the number of terminal rows the image spans. Not persisted, since it
	// depends on the current settings and is applied when the image is loaded.
	Rows int `json:"-"`
	// contains filtered or unexported fields
}

func (DecodedImage) DisplayUnicodePlaceholder

func (i DecodedImage) DisplayUnicodePlaceholder() string

DisplayUnicodePlaceholder returns the placeholder text for the last (bottom) row of the image, so the image is bottom aligned with the surrounding text. For multi-row images the rows above are derived via PlaceholderRowsAbove.

func (DecodedImage) PrepareCommand

func (i DecodedImage) PrepareCommand() string

type DecodedImageFrame

type DecodedImageFrame struct {
	Width       int    `json:"width"`
	Height      int    `json:"height"`
	EncodedPath string `json:"encoded_path"`
	DelayInMS   int    `json:"delay_in_ms"`
}

type DisplayManager

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

func NewDisplayManager

func NewDisplayManager(fs afero.Fs, cell CellSize, opts DisplayOptions) *DisplayManager

NewDisplayManager creates a display manager for a terminal with the given cell size in pixels.

func (*DisplayManager) CleanupAllImagesCommand

func (d *DisplayManager) CleanupAllImagesCommand() string

func (*DisplayManager) CleanupOldImagesCommand

func (d *DisplayManager) CleanupOldImagesCommand(maxAge time.Duration) string

func (*DisplayManager) Convert

func (d *DisplayManager) Convert(unit DisplayUnit) (KittyDisplayUnit, error)

func (*DisplayManager) RefreshCellSize added in v1.5.0

func (d *DisplayManager) RefreshCellSize()

RefreshCellSize re-reads the terminal cell size. Images that are converted afterwards use the new size; images already placed in this session keep their geometry, because their placeholder cells and placement are already in the rendered chat and cannot be re-laid-out.

type DisplayOptions added in v1.4.0

type DisplayOptions struct {
	Rows int // terminal rows an image spans, clamped to [1, MaxRows]

	// Passthrough wraps every kitty command for tmux's allow-passthrough mode.
	Passthrough bool

	// CellSize, when set, re-reads the terminal cell size on RefreshCellSize so
	// images converted after a resize or font change keep their aspect ratio.
	CellSize func() (CellSize, error)
}

DisplayOptions configures how images are displayed.

type DisplayUnit

type DisplayUnit struct {
	ID           string
	Directory    string
	IsAnimated   bool
	RightPadding int                                   // pixels of transparent padding to add on right side
	Load         func() (io.ReadCloser, string, error) `json:"-"`
}

type KittyDisplayUnit

type KittyDisplayUnit struct {
	PrepareCommand  string
	ReplacementText string
}

type PlaceholderSpan added in v1.5.0

type PlaceholderSpan struct {
	Col   int   // first terminal column of the run
	Width int   // number of cells in the run
	ID    int32 // image ID encoded in the foreground color
}

PlaceholderSpan is a run of adjacent placeholder cells belonging to one image.

func PlaceholderSpans added in v1.5.0

func PlaceholderSpans(line string) []PlaceholderSpan

PlaceholderSpans returns the image placeholder runs in a rendered line, with their terminal columns. Returns nil when line contains no placeholders.

Jump to

Keyboard shortcuts

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