diff --git a/CHANGES.md b/CHANGES.md index f37f02c..b58ab1b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,10 @@ * chore: drop dune as a dependency to fix .opam files +* feat: create colors from RGB tuples + +* feat: pretty print colors + ## 0.0.1 Initial release, including: diff --git a/tty/color.ml b/tty/color.ml index a4b2099..cb01aad 100644 --- a/tty/color.ml +++ b/tty/color.ml @@ -1,5 +1,12 @@ type t = RGB of int * int * int | ANSI of int | ANSI256 of int | No_color +let pp fmt t = + match t with + | RGB (r, g, b) -> Format.fprintf fmt "RGB(%d,%d,%d)" r g b + | ANSI i -> Format.fprintf fmt "ANSI(%d)" i + | ANSI256 i -> Format.fprintf fmt "ANSI256(%d)" i + | No_color -> Format.fprintf fmt "No_color" + exception Invalid_color of string exception Invalid_color_param of string exception Invalid_color_num of string * int diff --git a/tty/color.mli b/tty/color.mli index 501d0ab..5a42595 100644 --- a/tty/color.mli +++ b/tty/color.mli @@ -5,7 +5,8 @@ type t = private | No_color val make : string -> t -val of_rgb : (int * int * int) -> t +val of_rgb : int * int * int -> t +val pp : Format.formatter -> t -> unit exception Invalid_color of string exception Invalid_color_param of string