A CLI and OCaml library for managing contacts
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

more

+25 -7
+25 -7
lib/sortal_cmd.ml
··· 6 6 let use_graphics mode = 7 7 Kgp.Terminal.supports_graphics mode 8 8 9 - let next_image_id = ref 1 9 + (* Generate image IDs suitable for unicode placeholders. 10 + The ID must have non-zero bytes in positions for: 11 + - High byte (bits 24-31) - encoded as third diacritic 12 + - Middle bytes (bits 8-23) - encoded in foreground RGB color 13 + See kitty icat transmit.go for reference. *) 14 + let next_unicode_image_id () = 15 + (* Use Random to generate IDs with non-zero bytes in required positions *) 16 + let rec gen () = 17 + let id = Random.int32 Int32.max_int |> Int32.to_int in 18 + (* Ensure high byte and middle bytes are non-zero *) 19 + if id land 0xFF000000 = 0 || id land 0x00FFFF00 = 0 then gen () 20 + else id 21 + in 22 + gen () 10 23 11 24 let display_png_thumbnail path = 25 + let image_id = next_unicode_image_id () in 12 26 let png_data = Eio.Path.load path in 13 27 let rows = 4 in 14 28 let cols = 8 in 15 - (* Direct rendering - cursor stays in place after image *) 16 - let placement = Kgp.Placement.make ~rows ~columns:cols ~cursor:`Static () in 17 - let cmd = Kgp.transmit_and_display ~format:`Png ~placement ~quiet:`Silent () in 29 + (* Unicode placeholder mode - transmit image virtually, display via placeholders *) 30 + let placement = Kgp.Placement.make ~rows ~columns:cols ~unicode_placeholder:true () in 31 + let cmd = Kgp.transmit_and_display ~image_id ~format:`Png ~placement ~quiet:`Silent () in 18 32 let buf = Buffer.create 4096 in 33 + (* Transmit image with tmux passthrough if needed *) 19 34 Kgp.write_tmux buf cmd ~data:png_data; 35 + (* Write unicode placeholders - these are just text characters *) 36 + Kgp.Unicode_placeholder.write buf ~image_id ~rows ~cols (); 37 + (* Move cursor back up to top of image area and to column 0 *) 38 + Printf.bprintf buf "\x1b[%dA\r" (rows - 1); 20 39 Buffer.contents buf 21 40 22 41 let display_block_placeholder () = ··· 25 44 let row2 = "▒░▒▓▒░" in 26 45 let row3 = "░▒▓▒░▒" in 27 46 let row4 = "▒▓▒░▒▓" in 28 - Printf.sprintf "%s\n%s\n%s\n%s\x1b[4A" row1 row2 row3 row4 (* print 4 rows, move up 4 *) 47 + Printf.sprintf "%s\n%s\n%s\n%s\x1b[4A\r" row1 row2 row3 row4 (* print 4 rows, move up 4, return to col 0 *) 29 48 30 49 let move_right n = Printf.sprintf "\x1b[%dC" n 31 50 let move_down_and_back () = Printf.sprintf "\n\x1b[%dC" image_columns ··· 34 53 35 54 (* 1-row thumbnail for listings *) 36 55 let display_small_thumbnail path = 37 - let image_id = !next_image_id in 38 - incr next_image_id; 56 + let image_id = next_unicode_image_id () in 39 57 let png_data = Eio.Path.load path in 40 58 let rows = 1 in 41 59 let cols = 2 in