MCPcopy
hub / github.com/yorukot/superfile / buildKittyPlaceholders

Function buildKittyPlaceholders

src/pkg/file_preview/kitty.go:143–174  ·  view source on GitHub ↗

buildKittyPlaceholders builds a string of Kitty Unicode placeholder characters that the terminal replaces with the transmitted image.

(imgID int, cols, rows int)

Source from the content-addressed store, hash-verified

141// buildKittyPlaceholders builds a string of Kitty Unicode placeholder characters
142// that the terminal replaces with the transmitted image.
143func buildKittyPlaceholders(imgID int, cols, rows int) string {
144 // Encode image ID as foreground color for the placeholder cells.
145 // The terminal uses this color to identify which image to display.
146 r, g, b := byte((imgID>>rgbShift16)&rgbMask), byte((imgID>>rgbShift8)&rgbMask), byte(imgID&rgbMask)
147
148 var fgSeq string
149 if r == 0 && g == 0 {
150 // Use 256-color mode for small IDs
151 fgSeq = fmt.Sprintf("\x1b[38;5;%dm", b)
152 } else {
153 fgSeq = fmt.Sprintf("\x1b[38;2;%d;%d;%dm", r, g, b)
154 }
155 resetSeq := "\x1b[39m"
156
157 var buf strings.Builder
158 for y := range rows {
159 if y > 0 {
160 buf.WriteByte('\n')
161 }
162 buf.WriteString(fgSeq)
163 // First cell per row gets placeholder + row diacritic + col(0) diacritic
164 buf.WriteRune(kitty.Placeholder)
165 buf.WriteRune(kitty.Diacritic(y))
166 buf.WriteRune(kitty.Diacritic(0))
167 // Subsequent cells just get the placeholder
168 for x := 1; x < cols; x++ {
169 buf.WriteRune(kitty.Placeholder)
170 }
171 buf.WriteString(resetSeq)
172 }
173 return buf.String()
174}
175
176// IsKittyCapable checks if the terminal supports Kitty graphics protocol
177func (p *ImagePreviewer) IsKittyCapable() bool {

Callers 1

Calls 1

StringMethod · 0.65

Tested by

no test coverage detected