ohlog/lib/ansi.ml

32 lines
661 B
OCaml
Raw Permalink Normal View History

type ctl =
| Bold of bool
| Fg of color option
and color = R | G | Y | U | C
type t = ctl list
let string_of_ctl = function
| Bold true -> "1"
| Bold false -> "22"
(* | Fg (Some B) -> "30" *)
| Fg (Some R) -> "31"
| Fg (Some G) -> "32"
| Fg (Some Y) -> "33"
| Fg (Some U) -> "34"
(* | Fg (Some M) -> "35" *)
| Fg (Some C) -> "36"
(* | Fg (Some W) -> "37" *)
| Fg None -> "39"
let rec pr_rec pb pre suf = function
| [] ->
Buffer.add_string pb suf
| ctl :: ctls ->
Buffer.add_string pb pre;
Buffer.add_string pb (string_of_ctl ctl);
pr_rec pb ";" "m" ctls
let pr pb ctls =
pr_rec pb "\x1b[" "" ctls