Kitty Graphics Protocol in OCaml
terminal graphics ocaml
1(* Tmux Passthrough Support - Implementation *) 2 3let is_active () = 4 Option.is_some (Sys.getenv_opt "TMUX") 5 6let write_wrapped buf s = 7 (* DCS passthrough prefix: ESC P tmux ; *) 8 Buffer.add_string buf "\027Ptmux;"; 9 (* Double all ESC characters in the content *) 10 String.iter (fun c -> 11 if c = '\027' then Buffer.add_string buf "\027\027" 12 else Buffer.add_char buf c 13 ) s; 14 (* DCS terminator: ESC \ *) 15 Buffer.add_string buf "\027\\" 16 17let wrap_always s = 18 let buf = Buffer.create (String.length s * 2 + 10) in 19 write_wrapped buf s; 20 Buffer.contents buf 21 22let wrap s = 23 if is_active () then wrap_always s else s