Documentation
¶
Overview ¶
Package kitty provides Kitty terminal graphics protocol functionality.
Index ¶
Constants ¶
const ( // 32-bit RGBA format. RGBA = 32 // 24-bit RGB format. RGB = 24 // PNG format. PNG = 100 )
Graphics image format.
const ( // The data transmitted directly in the escape sequence. Direct = 'd' // The data transmitted in a regular file. File = 'f' // A temporary file is used and deleted after transmission. TempFile = 't' // For POSIX see https://pubs.opengroup.org/onlinepubs/9699919799/functions/shm_open.html // For Windows see https://docs.microsoft.com/en-us/windows/win32/memory/creating-named-shared-memory SharedMemory = 's' )
Transmission types.
const ( // Transmit image data. Transmit = 't' // TransmitAndPut transmit image data and display (put) it. TransmitAndPut = 'T' // Query terminal for image info. Query = 'q' // Put (display) previously transmitted image. Put = 'p' // Delete image. Delete = 'd' // Frame transmits data for animation frames. Frame = 'f' // Animate controls animation. Animate = 'a' // Compose composes animation frames. Compose = 'c' )
Action types.
const ( // Delete all placements visible on screen. DeleteAll = 'a' // Delete all images with the specified id, specified using the i key. If // you specify a p key for the placement id as well, then only the // placement with the specified image id and placement id will be deleted. DeleteID = 'i' // Delete newest image with the specified number, specified using the I // key. If you specify a p key for the placement id as well, then only the // placement with the specified number and placement id will be deleted. DeleteNumber = 'n' // Delete all placements that intersect with the current cursor position. DeleteCursor = 'c' // Delete animation frames. DeleteFrames = 'f' // Delete all placements that intersect a specific cell, the cell is // specified using the x and y keys. DeleteCell = 'p' // Delete all placements that intersect a specific cell having a specific // z-index. The cell and z-index is specified using the x, y and z keys. DeleteCellZ = 'q' // Delete all images whose id is greater than or equal to the value of the x // key and less than or equal to the value of the y. DeleteRange = 'r' // Delete all placements that intersect the specified column, specified using // the x key. DeleteColumn = 'x' // Delete all placements that intersect the specified row, specified using // the y key. DeleteRow = 'y' // Delete all placements that have the specified z-index, specified using the // z key. DeleteZ = 'z' )
Delete types.
const MaxChunkSize = 1024 * 4
MaxChunkSize is the maximum chunk size for the image data.
const Placeholder = '\U0010EEEE'
Placeholder is a special Unicode character that can be used as a placeholder for an image.
const (
Zlib = 'z'
)
Compression types.
Variables ¶
var ( // GraphicsTempDir is the directory where temporary files are stored. // This is used in [WriteKittyGraphics] along with [os.CreateTemp]. GraphicsTempDir = "" // GraphicsTempPattern is the pattern used to create temporary files. // This is used in [WriteKittyGraphics] along with [os.CreateTemp]. // The Kitty Graphics protocol requires the file path to contain the // substring "tty-graphics-protocol". GraphicsTempPattern = "tty-graphics-protocol-*" )
var ErrMissingFile = errors.New("missing file path")
ErrMissingFile is returned when the file path is missing.
Functions ¶
func Diacritic ¶
Diacritic returns the diacritic rune at the specified index. If the index is out of bounds, the first diacritic rune is returned.
func EncodeGraphics ¶ added in v0.9.4
EncodeGraphics writes an image using the Kitty Graphics protocol with the given options to w. It chunks the written data if o.Chunk is true.
You can omit m and use nil when rendering an image from a file. In this case, you must provide a file path in o.File and use o.Transmission = File. You can also use o.Transmission = TempFile to write the image to a temporary file. In that case, the file path is ignored, and the image is written to a temporary file that is automatically deleted by the terminal.
Types ¶
type Decoder ¶
type Decoder struct {
// Uses zlib decompression.
Decompress bool
// Can be one of [RGB], [RGBA], or [PNG].
Format int
// Width of the image in pixels. This can be omitted if the image is [PNG]
// formatted.
Width int
// Height of the image in pixels. This can be omitted if the image is [PNG]
// formatted.
Height int
}
Decoder is a decoder for the Kitty graphics protocol. It supports decoding images in the 24-bit RGB, 32-bit RGBA, and PNG formats. It can also decompress data using zlib. The default format is 32-bit RGBA.
type Encoder ¶
type Encoder struct {
// Uses zlib compression.
Compress bool
// Can be one of [RGBA], [RGB], or [PNG].
Format int
}
Encoder is an encoder for the Kitty graphics protocol. It supports encoding images in the 24-bit RGB, 32-bit RGBA, and PNG formats, and compressing the data using zlib. The default format is 32-bit RGBA.
type Options ¶
type Options struct {
// Action (a=t) is the action to be performed on the image. Can be one of
// [Transmit], [TransmitDisplay], [Query], [Put], [Delete], [Frame],
// [Animate], [Compose].
Action byte
// Quite mode (q=0) is the quiet mode. Can be either zero, one, or two
// where zero is the default, 1 suppresses OK responses, and 2 suppresses
// both OK and error responses.
Quite byte
// ID (i=) is the image ID. The ID is a unique identifier for the image.
// Must be a positive integer up to [math.MaxUint32].
ID int
// PlacementID (p=) is the placement ID. The placement ID is a unique
// identifier for the placement of the image. Must be a positive integer up
// to [math.MaxUint32].
PlacementID int
// Number (I=0) is the number of images to be transmitted.
Number int
// Format (f=32) is the image format. One of [RGBA], [RGB], [PNG].
Format int
// ImageWidth (s=0) is the transmitted image width.
ImageWidth int
// ImageHeight (v=0) is the transmitted image height.
ImageHeight int
// Compression (o=) is the image compression type. Can be [Zlib] or zero.
Compression byte
// Transmission (t=d) is the image transmission type. Can be [Direct], [File],
// [TempFile], or[SharedMemory].
Transmission byte
// File is the file path to be used when the transmission type is [File].
// If [Options.Transmission] is omitted i.e. zero and this is non-empty,
// the transmission type is set to [File].
File string
// Size (S=0) is the size to be read from the transmission medium.
Size int
// Offset (O=0) is the offset byte to start reading from the transmission
// medium.
Offset int
// Chunk (m=) whether the image is transmitted in chunks. Can be either
// zero or one. When true, the image is transmitted in chunks. Each chunk
// must be a multiple of 4, and up to [MaxChunkSize] bytes. Each chunk must
// have the m=1 option except for the last chunk which must have m=0.
Chunk bool
// ChunkFormatter is the function used to format each chunk when
// [Options.Chunk] is true. If nil, the chunks are sent as is.
ChunkFormatter func(chunk string) string
// X (x=0) is the pixel X coordinate of the image to start displaying.
X int
// Y (y=0) is the pixel Y coordinate of the image to start displaying.
Y int
// Z (z=0) is the Z coordinate of the image to display.
Z int
// Width (w=0) is the width of the image to display.
Width int
// Height (h=0) is the height of the image to display.
Height int
// OffsetX (X=0) is the OffsetX coordinate of the cursor cell to start
// displaying the image. OffsetX=0 is the leftmost cell. This must be
// smaller than the terminal cell width.
OffsetX int
// OffsetY (Y=0) is the OffsetY coordinate of the cursor cell to start
// displaying the image. OffsetY=0 is the topmost cell. This must be
// smaller than the terminal cell height.
OffsetY int
// Columns (c=0) is the number of columns to display the image. The image
// will be scaled to fit the number of columns.
Columns int
// Rows (r=0) is the number of rows to display the image. The image will be
// scaled to fit the number of rows.
Rows int
// VirtualPlacement (U=0) whether to use virtual placement. This is used
// with Unicode [Placeholder] to display images.
VirtualPlacement bool
// DoNotMoveCursor (C=0) whether to move the cursor after displaying the
// image.
DoNotMoveCursor bool
// ParentID (P=0) is the parent image ID. The parent ID is the ID of the
// image that is the parent of the current image. This is used with Unicode
// [Placeholder] to display images relative to the parent image.
ParentID int
// ParentPlacementID (Q=0) is the parent placement ID. The parent placement
// ID is the ID of the placement of the parent image. This is used with
// Unicode [Placeholder] to display images relative to the parent image.
ParentPlacementID int
// Delete (d=a) is the delete action. Can be one of [DeleteAll],
// [DeleteID], [DeleteNumber], [DeleteCursor], [DeleteFrames],
// [DeleteCell], [DeleteCellZ], [DeleteRange], [DeleteColumn], [DeleteRow],
// [DeleteZ].
Delete byte
// DeleteResources indicates whether to delete the resources associated
// with the image.
DeleteResources bool
}
Options represents a Kitty Graphics Protocol options.
func (Options) MarshalText ¶
MarshalText returns the string representation of the options.
func (*Options) UnmarshalText ¶
UnmarshalText parses the options from the given string.