(
base64Data: string,
options: {
columns?: number;
rows?: number;
imageId?: number;
/** Whether Kitty should apply its default cursor movement after placement. Default: true. */
moveCursor?: boolean;
} = {},
)
| 163 | } |
| 164 | |
| 165 | export function encodeKitty( |
| 166 | base64Data: string, |
| 167 | options: { |
| 168 | columns?: number; |
| 169 | rows?: number; |
| 170 | imageId?: number; |
| 171 | /** Whether Kitty should apply its default cursor movement after placement. Default: true. */ |
| 172 | moveCursor?: boolean; |
| 173 | } = {}, |
| 174 | ): string { |
| 175 | const CHUNK_SIZE = 4096; |
| 176 | |
| 177 | const params: string[] = ["a=T", "f=100", "q=2"]; |
| 178 | |
| 179 | if (options.moveCursor === false) params.push("C=1"); |
| 180 | if (options.columns) params.push(`c=${options.columns}`); |
| 181 | if (options.rows) params.push(`r=${options.rows}`); |
| 182 | if (options.imageId) params.push(`i=${options.imageId}`); |
| 183 | |
| 184 | if (base64Data.length <= CHUNK_SIZE) { |
| 185 | return `\x1b_G${params.join(",")};${base64Data}\x1b\\`; |
| 186 | } |
| 187 | |
| 188 | const chunks: string[] = []; |
| 189 | let offset = 0; |
| 190 | let isFirst = true; |
| 191 | |
| 192 | while (offset < base64Data.length) { |
| 193 | const chunk = base64Data.slice(offset, offset + CHUNK_SIZE); |
| 194 | const isLast = offset + CHUNK_SIZE >= base64Data.length; |
| 195 | |
| 196 | if (isFirst) { |
| 197 | chunks.push(`\x1b_G${params.join(",")},m=1;${chunk}\x1b\\`); |
| 198 | isFirst = false; |
| 199 | } else if (isLast) { |
| 200 | chunks.push(`\x1b_Gm=0;${chunk}\x1b\\`); |
| 201 | } else { |
| 202 | chunks.push(`\x1b_Gm=1;${chunk}\x1b\\`); |
| 203 | } |
| 204 | |
| 205 | offset += CHUNK_SIZE; |
| 206 | } |
| 207 | |
| 208 | return chunks.join(""); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Delete a Kitty graphics image by ID. |
no test coverage detected