| 1 |
package kitty |
| 2 |
|
| 3 |
import "errors" |
| 4 |
|
| 5 |
// ErrMissingFile is returned when the file path is missing. |
| 6 |
var ErrMissingFile = errors.New("missing file path") |
| 7 |
|
| 8 |
// MaxChunkSize is the maximum chunk size for the image data. |
| 9 |
const MaxChunkSize = 1024 * 4 |
| 10 |
|
| 11 |
// Placeholder is a special Unicode character that can be used as a placeholder |
| 12 |
// for an image. |
| 13 |
const Placeholder = '\U0010EEEE' |
| 14 |
|
| 15 |
// Graphics image format. |
| 16 |
const ( |
| 17 |
// 32-bit RGBA format. |
| 18 |
RGBA = 32 |
| 19 |
|
| 20 |
// 24-bit RGB format. |
| 21 |
RGB = 24 |
| 22 |
|
| 23 |
// PNG format. |
| 24 |
PNG = 100 |
| 25 |
) |
| 26 |
|
| 27 |
// Compression types. |
| 28 |
const ( |
| 29 |
Zlib = 'z' |
| 30 |
) |
| 31 |
|
| 32 |
// Transmission types. |
| 33 |
const ( |
| 34 |
// The data transmitted directly in the escape sequence. |
| 35 |
Direct = 'd' |
| 36 |
|
| 37 |
// The data transmitted in a regular file. |
| 38 |
File = 'f' |
| 39 |
|
| 40 |
// A temporary file is used and deleted after transmission. |
| 41 |
TempFile = 't' |
| 42 |
|
| 43 |
// A shared memory object. |
| 44 |
// For POSIX see https://pubs.opengroup.org/onlinepubs/9699919799/functions/shm_open.html |
| 45 |
// For Windows see https://docs.microsoft.com/en-us/windows/win32/memory/creating-named-shared-memory |
| 46 |
SharedMemory = 's' |
| 47 |
) |
| 48 |
|
| 49 |
// Action types. |
| 50 |
const ( |
| 51 |
// Transmit image data. |
| 52 |
Transmit = 't' |
| 53 |
// TransmitAndPut transmit image data and display (put) it. |
| 54 |
TransmitAndPut = 'T' |
| 55 |
// Query terminal for image info. |
| 56 |
Query = 'q' |
| 57 |
// Put (display) previously transmitted image. |
| 58 |
Put = 'p' |
| 59 |
// Delete image. |
| 60 |
Delete = 'd' |
| 61 |
// Frame transmits data for animation frames. |
| 62 |
Frame = 'f' |
| 63 |
// Animate controls animation. |
| 64 |
Animate = 'a' |
| 65 |
// Compose composes animation frames. |
| 66 |
Compose = 'c' |
| 67 |
) |
| 68 |
|
| 69 |
// Delete types. |
| 70 |
const ( |
| 71 |
// Delete all placements visible on screen. |
| 72 |
DeleteAll = 'a' |
| 73 |
// Delete all images with the specified id, specified using the i key. If |
| 74 |
// you specify a p key for the placement id as well, then only the |
| 75 |
// placement with the specified image id and placement id will be deleted. |
| 76 |
DeleteID = 'i' |
| 77 |
// Delete newest image with the specified number, specified using the I |
| 78 |
// key. If you specify a p key for the placement id as well, then only the |
| 79 |
// placement with the specified number and placement id will be deleted. |
| 80 |
DeleteNumber = 'n' |
| 81 |
// Delete all placements that intersect with the current cursor position. |
| 82 |
DeleteCursor = 'c' |
| 83 |
// Delete animation frames. |
| 84 |
DeleteFrames = 'f' |
| 85 |
// Delete all placements that intersect a specific cell, the cell is |
| 86 |
// specified using the x and y keys. |
| 87 |
DeleteCell = 'p' |
| 88 |
// Delete all placements that intersect a specific cell having a specific |
| 89 |
// z-index. The cell and z-index is specified using the x, y and z keys. |
| 90 |
DeleteCellZ = 'q' |
| 91 |
// Delete all images whose id is greater than or equal to the value of the x |
| 92 |
// key and less than or equal to the value of the y. |
| 93 |
DeleteRange = 'r' |
| 94 |
// Delete all placements that intersect the specified column, specified using |
| 95 |
// the x key. |
| 96 |
DeleteColumn = 'x' |
| 97 |
// Delete all placements that intersect the specified row, specified using |
| 98 |
// the y key. |
| 99 |
DeleteRow = 'y' |
| 100 |
// Delete all placements that have the specified z-index, specified using the |
| 101 |
// z key. |
| 102 |
DeleteZ = 'z' |
| 103 |
) |
| 104 |
|
| 105 |
// Diacritic returns the diacritic rune at the specified index. If the index is |
| 106 |
// out of bounds, the first diacritic rune is returned. |
| 107 |
func Diacritic(i int) rune { |
| 108 |
if i < 0 || i >= len(diacritics) { |
| 109 |
return diacritics[0] |
| 110 |
} |
| 111 |
return diacritics[i] |
| 112 |
} |
| 113 |
|
| 114 |
// From https://sw.kovidgoyal.net/kitty/_downloads/f0a0de9ec8d9ff4456206db8e0814937/rowcolumn-diacritics.txt |
| 115 |
// See https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders for further explanation. |
| 116 |
var diacritics = []rune{ |
| 117 |
'\u0305', |
| 118 |
'\u030D', |
| 119 |
'\u030E', |
| 120 |
'\u0310', |
| 121 |
'\u0312', |
| 122 |
'\u033D', |
| 123 |
'\u033E', |
| 124 |
'\u033F', |
| 125 |
'\u0346', |
| 126 |
'\u034A', |
| 127 |
'\u034B', |
| 128 |
'\u034C', |
| 129 |
'\u0350', |
| 130 |
'\u0351', |
| 131 |
'\u0352', |
| 132 |
'\u0357', |
| 133 |
'\u035B', |
| 134 |
'\u0363', |
| 135 |
'\u0364', |
| 136 |
'\u0365', |
| 137 |
'\u0366', |
| 138 |
'\u0367', |
| 139 |
'\u0368', |
| 140 |
'\u0369', |
| 141 |
'\u036A', |
| 142 |
'\u036B', |
| 143 |
'\u036C', |
| 144 |
'\u036D', |
| 145 |
'\u036E', |
| 146 |
'\u036F', |
| 147 |
'\u0483', |
| 148 |
'\u0484', |
| 149 |
'\u0485', |
| 150 |
'\u0486', |
| 151 |
'\u0487', |
| 152 |
'\u0592', |
| 153 |
'\u0593', |
| 154 |
'\u0594', |
| 155 |
'\u0595', |
| 156 |
'\u0597', |
| 157 |
'\u0598', |
| 158 |
'\u0599', |
| 159 |
'\u059C', |
| 160 |
'\u059D', |
| 161 |
'\u059E', |
| 162 |
'\u059F', |
| 163 |
'\u05A0', |
| 164 |
'\u05A1', |
| 165 |
'\u05A8', |
| 166 |
'\u05A9', |
| 167 |
'\u05AB', |
| 168 |
'\u05AC', |
| 169 |
'\u05AF', |
| 170 |
'\u05C4', |
| 171 |
'\u0610', |
| 172 |
'\u0611', |
| 173 |
'\u0612', |
| 174 |
'\u0613', |
| 175 |
'\u0614', |
| 176 |
'\u0615', |
| 177 |
'\u0616', |
| 178 |
'\u0617', |
| 179 |
'\u0657', |
| 180 |
'\u0658', |
| 181 |
'\u0659', |
| 182 |
'\u065A', |
| 183 |
'\u065B', |
| 184 |
'\u065D', |
| 185 |
'\u065E', |
| 186 |
'\u06D6', |
| 187 |
'\u06D7', |
| 188 |
'\u06D8', |
| 189 |
'\u06D9', |
| 190 |
'\u06DA', |
| 191 |
'\u06DB', |
| 192 |
'\u06DC', |
| 193 |
'\u06DF', |
| 194 |
'\u06E0', |
| 195 |
'\u06E1', |
| 196 |
'\u06E2', |
| 197 |
'\u06E4', |
| 198 |
'\u06E7', |
| 199 |
'\u06E8', |
| 200 |
'\u06EB', |
| 201 |
'\u06EC', |
| 202 |
'\u0730', |
| 203 |
'\u0732', |
| 204 |
'\u0733', |
| 205 |
'\u0735', |
| 206 |
'\u0736', |
| 207 |
'\u073A', |
| 208 |
'\u073D', |
| 209 |
'\u073F', |
| 210 |
'\u0740', |
| 211 |
'\u0741', |
| 212 |
'\u0743', |
| 213 |
'\u0745', |
| 214 |
'\u0747', |
| 215 |
'\u0749', |
| 216 |
'\u074A', |
| 217 |
'\u07EB', |
| 218 |
'\u07EC', |
| 219 |
'\u07ED', |
| 220 |
'\u07EE', |
| 221 |
'\u07EF', |
| 222 |
'\u07F0', |
| 223 |
'\u07F1', |
| 224 |
'\u07F3', |
| 225 |
'\u0816', |
| 226 |
'\u0817', |
| 227 |
'\u0818', |
| 228 |
'\u0819', |
| 229 |
'\u081B', |
| 230 |
'\u081C', |
| 231 |
'\u081D', |
| 232 |
'\u081E', |
| 233 |
'\u081F', |
| 234 |
'\u0820', |
| 235 |
'\u0821', |
| 236 |
'\u0822', |
| 237 |
'\u0823', |
| 238 |
'\u0825', |
| 239 |
'\u0826', |
| 240 |
'\u0827', |
| 241 |
'\u0829', |
| 242 |
'\u082A', |
| 243 |
'\u082B', |
| 244 |
'\u082C', |
| 245 |
'\u082D', |
| 246 |
'\u0951', |
| 247 |
'\u0953', |
| 248 |
'\u0954', |
| 249 |
'\u0F82', |
| 250 |
'\u0F83', |
| 251 |
'\u0F86', |
| 252 |
'\u0F87', |
| 253 |
'\u135D', |
| 254 |
'\u135E', |
| 255 |
'\u135F', |
| 256 |
'\u17DD', |
| 257 |
'\u193A', |
| 258 |
'\u1A17', |
| 259 |
'\u1A75', |
| 260 |
'\u1A76', |
| 261 |
'\u1A77', |
| 262 |
'\u1A78', |
| 263 |
'\u1A79', |
| 264 |
'\u1A7A', |
| 265 |
'\u1A7B', |
| 266 |
'\u1A7C', |
| 267 |
'\u1B6B', |
| 268 |
'\u1B6D', |
| 269 |
'\u1B6E', |
| 270 |
'\u1B6F', |
| 271 |
'\u1B70', |
| 272 |
'\u1B71', |
| 273 |
'\u1B72', |
| 274 |
'\u1B73', |
| 275 |
'\u1CD0', |
| 276 |
'\u1CD1', |
| 277 |
'\u1CD2', |
| 278 |
'\u1CDA', |
| 279 |
'\u1CDB', |
| 280 |
'\u1CE0', |
| 281 |
'\u1DC0', |
| 282 |
'\u1DC1', |
| 283 |
'\u1DC3', |
| 284 |
'\u1DC4', |
| 285 |
'\u1DC5', |
| 286 |
'\u1DC6', |
| 287 |
'\u1DC7', |
| 288 |
'\u1DC8', |
| 289 |
'\u1DC9', |
| 290 |
'\u1DCB', |
| 291 |
'\u1DCC', |
| 292 |
'\u1DD1', |
| 293 |
'\u1DD2', |
| 294 |
'\u1DD3', |
| 295 |
'\u1DD4', |
| 296 |
'\u1DD5', |
| 297 |
'\u1DD6', |
| 298 |
'\u1DD7', |
| 299 |
'\u1DD8', |
| 300 |
'\u1DD9', |
| 301 |
'\u1DDA', |
| 302 |
'\u1DDB', |
| 303 |
'\u1DDC', |
| 304 |
'\u1DDD', |
| 305 |
'\u1DDE', |
| 306 |
'\u1DDF', |
| 307 |
'\u1DE0', |
| 308 |
'\u1DE1', |
| 309 |
'\u1DE2', |
| 310 |
'\u1DE3', |
| 311 |
'\u1DE4', |
| 312 |
'\u1DE5', |
| 313 |
'\u1DE6', |
| 314 |
'\u1DFE', |
| 315 |
'\u20D0', |
| 316 |
'\u20D1', |
| 317 |
'\u20D4', |
| 318 |
'\u20D5', |
| 319 |
'\u20D6', |
| 320 |
'\u20D7', |
| 321 |
'\u20DB', |
| 322 |
'\u20DC', |
| 323 |
'\u20E1', |
| 324 |
'\u20E7', |
| 325 |
'\u20E9', |
| 326 |
'\u20F0', |
| 327 |
'\u2CEF', |
| 328 |
'\u2CF0', |
| 329 |
'\u2CF1', |
| 330 |
'\u2DE0', |
| 331 |
'\u2DE1', |
| 332 |
'\u2DE2', |
| 333 |
'\u2DE3', |
| 334 |
'\u2DE4', |
| 335 |
'\u2DE5', |
| 336 |
'\u2DE6', |
| 337 |
'\u2DE7', |
| 338 |
'\u2DE8', |
| 339 |
'\u2DE9', |
| 340 |
'\u2DEA', |
| 341 |
'\u2DEB', |
| 342 |
'\u2DEC', |
| 343 |
'\u2DED', |
| 344 |
'\u2DEE', |
| 345 |
'\u2DEF', |
| 346 |
'\u2DF0', |
| 347 |
'\u2DF1', |
| 348 |
'\u2DF2', |
| 349 |
'\u2DF3', |
| 350 |
'\u2DF4', |
| 351 |
'\u2DF5', |
| 352 |
'\u2DF6', |
| 353 |
'\u2DF7', |
| 354 |
'\u2DF8', |
| 355 |
'\u2DF9', |
| 356 |
'\u2DFA', |
| 357 |
'\u2DFB', |
| 358 |
'\u2DFC', |
| 359 |
'\u2DFD', |
| 360 |
'\u2DFE', |
| 361 |
'\u2DFF', |
| 362 |
'\uA66F', |
| 363 |
'\uA67C', |
| 364 |
'\uA67D', |
| 365 |
'\uA6F0', |
| 366 |
'\uA6F1', |
| 367 |
'\uA8E0', |
| 368 |
'\uA8E1', |
| 369 |
'\uA8E2', |
| 370 |
'\uA8E3', |
| 371 |
'\uA8E4', |
| 372 |
'\uA8E5', |
| 373 |
'\uA8E6', |
| 374 |
'\uA8E7', |
| 375 |
'\uA8E8', |
| 376 |
'\uA8E9', |
| 377 |
'\uA8EA', |
| 378 |
'\uA8EB', |
| 379 |
'\uA8EC', |
| 380 |
'\uA8ED', |
| 381 |
'\uA8EE', |
| 382 |
'\uA8EF', |
| 383 |
'\uA8F0', |
| 384 |
'\uA8F1', |
| 385 |
'\uAAB0', |
| 386 |
'\uAAB2', |
| 387 |
'\uAAB3', |
| 388 |
'\uAAB7', |
| 389 |
'\uAAB8', |
| 390 |
'\uAABE', |
| 391 |
'\uAABF', |
| 392 |
'\uAAC1', |
| 393 |
'\uFE20', |
| 394 |
'\uFE21', |
| 395 |
'\uFE22', |
| 396 |
'\uFE23', |
| 397 |
'\uFE24', |
| 398 |
'\uFE25', |
| 399 |
'\uFE26', |
| 400 |
'\U00010A0F', |
| 401 |
'\U00010A38', |
| 402 |
'\U0001D185', |
| 403 |
'\U0001D186', |
| 404 |
'\U0001D187', |
| 405 |
'\U0001D188', |
| 406 |
'\U0001D189', |
| 407 |
'\U0001D1AA', |
| 408 |
'\U0001D1AB', |
| 409 |
'\U0001D1AC', |
| 410 |
'\U0001D1AD', |
| 411 |
'\U0001D242', |
| 412 |
'\U0001D243', |
| 413 |
'\U0001D244', |
| 414 |
} |