Kitty Graphics Protocol in OCaml
terminal graphics ocaml
1(* Simple test to show exact escape sequences without data *) 2 3module K = Kgp 4 5let print_escaped s = 6 String.iter (fun c -> 7 let code = Char.code c in 8 if code = 27 then print_string "\\x1b" 9 else if code < 32 || code > 126 then Printf.printf "\\x%02x" code 10 else print_char c 11 ) s; 12 print_newline () 13 14let () = 15 let image_id = 300 in 16 let width, height = 80, 80 in 17 18 print_endline "=== Animation Escape Sequences (no data) ===\n"; 19 20 (* 1. Transmit base frame (no data for testing) *) 21 print_endline "1. Transmit (a=t):"; 22 let cmd1 = K.Command.transmit 23 ~image_id ~format:`Rgba32 ~width ~height ~quiet:`Errors_only () in 24 print_escaped (K.Command.to_string cmd1 ~data:""); 25 26 (* 2. Frame command *) 27 print_endline "\n2. Frame (a=f):"; 28 let cmd2 = K.Command.frame 29 ~image_id ~format:`Rgba32 ~width ~height 30 ~frame:(K.Frame.make ~gap_ms:100 ~composition:`Overwrite ()) 31 ~quiet:`Errors_only () in 32 print_escaped (K.Command.to_string cmd2 ~data:""); 33 34 (* 3. Put/display command *) 35 print_endline "\n3. Display/Put (a=p):"; 36 let cmd3 = K.Command.display 37 ~image_id 38 ~placement:(K.Placement.make 39 ~placement_id:1 40 ~cell_x_offset:0 41 ~cell_y_offset:0 42 ~cursor:`Static ()) 43 ~quiet:`Errors_only () in 44 print_escaped (K.Command.to_string cmd3 ~data:""); 45 46 (* 4. Set root frame gap - IMPORTANT for animation! *) 47 print_endline "\n4. Set root frame gap (a=a, r=1, z=100):"; 48 let cmd4 = K.Command.animate ~image_id (K.Animation.set_gap ~frame:1 ~gap_ms:100) in 49 print_escaped (K.Command.to_string cmd4 ~data:""); 50 51 (* 5. Animate - start *) 52 print_endline "\n5. Animate start (a=a, s=3, v=1):"; 53 let cmd5 = K.Command.animate ~image_id (K.Animation.set_state ~loops:1 `Run) in 54 print_escaped (K.Command.to_string cmd5 ~data:""); 55 56 (* 6. Animate - stop *) 57 print_endline "\n6. Animate stop (a=a, s=1):"; 58 let cmd6 = K.Command.animate ~image_id (K.Animation.set_state `Stop) in 59 print_escaped (K.Command.to_string cmd6 ~data:"")