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