package kittyimport ()var ( _ encoding.TextMarshaler = Options{} _ encoding.TextUnmarshaler = &Options{})// Stringish is a type constraint for types that are either a string or a// byte slice.typeStringishinterface{ string | []byte }// Options represents a Kitty Graphics Protocol options.typeOptionsstruct {// Common options.// Action (a=t) is the action to be performed on the image. Can be one of // [Transmit], [TransmitDisplay], [Query], [Put], [Delete], [Frame], // [Animate], [Compose].Actionbyte// Quite is the kitty graphics quiet mode. // // Deprecated: misspelled field, use [Options.Quiet] instead. Any non-zero // Quite overrides Quiet.Quitebyte// Quiet 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.Quietbyte// Transmission options.// ID (i=) is the image ID. The ID is a unique identifier for the image. // Must be a positive integer up to [math.MaxUint32].IDint// 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].PlacementIDint// Number (I=0) is the number of images to be transmitted.Numberint// Format (f=32) is the image format. One of [RGBA], [RGB], [PNG].Formatint// ImageWidth (s=0) is the transmitted image width.ImageWidthint// ImageHeight (v=0) is the transmitted image height.ImageHeightint// Compression (o=) is the image compression type. Can be [Zlib] or zero.Compressionbyte// Transmission (t=d) is the image transmission type. Can be [Direct], [File], // [TempFile], or[SharedMemory].Transmissionbyte// 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].Filestring// Size (S=0) is the size to be read from the transmission medium.Sizeint// Offset (O=0) is the offset byte to start reading from the transmission // medium.Offsetint// 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.Chunkbool// ChunkFormatter is the function used to format each chunk when // [Options.Chunk] is true. If nil, the chunks are sent as is.ChunkFormatterfunc(chunk string) string// Display options.// X (x=0) is the pixel X coordinate of the image to start displaying.Xint// Y (y=0) is the pixel Y coordinate of the image to start displaying.Yint// Z (z=0) is the Z coordinate of the image to display.Zint// Width (w=0) is the width of the image to display.Widthint// Height (h=0) is the height of the image to display.Heightint// 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.OffsetXint// 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.OffsetYint// Columns (c=0) is the number of columns to display the image. The image // will be scaled to fit the number of columns.Columnsint// Rows (r=0) is the number of rows to display the image. The image will be // scaled to fit the number of rows.Rowsint// VirtualPlacement (U=0) whether to use virtual placement. This is used // with Unicode [Placeholder] to display images.VirtualPlacementbool// DoNotMoveCursor (C=0) whether to move the cursor after displaying the // image.DoNotMoveCursorbool// 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.ParentIDint// 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.ParentPlacementIDint// Delete options.// Delete (d=a) is the delete action. Can be one of [DeleteAll], // [DeleteID], [DeleteNumber], [DeleteCursor], [DeleteFrames], // [DeleteCell], [DeleteCellZ], [DeleteRange], [DeleteColumn], [DeleteRow], // [DeleteZ].Deletebyte// DeleteResources indicates whether to delete the resources associated // with the image.DeleteResourcesbool}// Options returns the options as a slice of a key-value pairs.func ( *Options) () ( []string) { = []string{}if .Format == 0 { .Format = RGBA }if .Action == 0 { .Action = Transmit }if .Delete == 0 { .Delete = DeleteAll }if .Transmission == 0 {iflen(.File) > 0 { .Transmission = File } else { .Transmission = Direct } }if .Format != RGBA { = append(, fmt.Sprintf("f=%d", .Format)) } := .Quietif .Quite > 0 {// handle deprecated Quite field. = .Quite }if > 0 { = append(, fmt.Sprintf("q=%d", )) }if .ID > 0 { = append(, fmt.Sprintf("i=%d", .ID)) }if .PlacementID > 0 { = append(, fmt.Sprintf("p=%d", .PlacementID)) }if .Number > 0 { = append(, fmt.Sprintf("I=%d", .Number)) }if .ImageWidth > 0 { = append(, fmt.Sprintf("s=%d", .ImageWidth)) }if .ImageHeight > 0 { = append(, fmt.Sprintf("v=%d", .ImageHeight)) }if .Transmission != Direct { = append(, fmt.Sprintf("t=%c", .Transmission)) }if .Size > 0 { = append(, fmt.Sprintf("S=%d", .Size)) }if .Offset > 0 { = append(, fmt.Sprintf("O=%d", .Offset)) }if .Compression == Zlib { = append(, fmt.Sprintf("o=%c", .Compression)) }if .VirtualPlacement { = append(, "U=1") }if .DoNotMoveCursor { = append(, "C=1") }if .ParentID > 0 { = append(, fmt.Sprintf("P=%d", .ParentID)) }if .ParentPlacementID > 0 { = append(, fmt.Sprintf("Q=%d", .ParentPlacementID)) }if .X > 0 { = append(, fmt.Sprintf("x=%d", .X)) }if .Y > 0 { = append(, fmt.Sprintf("y=%d", .Y)) }if .Z > 0 { = append(, fmt.Sprintf("z=%d", .Z)) }if .Width > 0 { = append(, fmt.Sprintf("w=%d", .Width)) }if .Height > 0 { = append(, fmt.Sprintf("h=%d", .Height)) }if .OffsetX > 0 { = append(, fmt.Sprintf("X=%d", .OffsetX)) }if .OffsetY > 0 { = append(, fmt.Sprintf("Y=%d", .OffsetY)) }if .Columns > 0 { = append(, fmt.Sprintf("c=%d", .Columns)) }if .Rows > 0 { = append(, fmt.Sprintf("r=%d", .Rows)) }if .Delete != DeleteAll || .DeleteResources { := .Deleteif .DeleteResources { = - ' '// to uppercase } = append(, fmt.Sprintf("d=%c", )) }if .Action != Transmit { = append(, fmt.Sprintf("a=%c", .Action)) }return// complex function with multiple returns}// String returns the string representation of the options.func ( Options) () string {returnstrings.Join(.Options(), ",")}// MarshalText returns the string representation of the options.func ( Options) () ([]byte, error) {return []byte(.String()), nil}// UnmarshalText parses the options from the given string.func ( *Options) ( []byte) error { := strings.Split(string(), ",")for , := range { := strings.SplitN(, "=", 2)iflen() != 2 || len([1]) == 0 {continue }switch [0] {case"a": .Action = [1][0]case"o": .Compression = [1][0]case"t": .Transmission = [1][0]case"d": := [1][0]if >= 'A' && <= 'Z' { .DeleteResources = true = + ' '// to lowercase } .Delete = case"i", "q", "p", "I", "f", "s", "v", "S", "O", "m", "x", "y", "z", "w", "h", "X", "Y", "c", "r", "U", "P", "Q": , := strconv.Atoi([1])if != nil {continue }switch [0] {case"i": .ID = case"q": .Quiet = byte() //nolint:goseccase"p": .PlacementID = case"I": .Number = case"f": .Format = case"s": .ImageWidth = case"v": .ImageHeight = case"S": .Size = case"O": .Offset = case"m": .Chunk = == 0 || == 1case"x": .X = case"y": .Y = case"z": .Z = case"w": .Width = case"h": .Height = case"X": .OffsetX = case"Y": .OffsetY = case"c": .Columns = case"r": .Rows = case"U": .VirtualPlacement = == 1case"P": .ParentID = case"Q": .ParentPlacementID = } } }returnnil}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)