Skip to content

Commit

Permalink
feat: export pretty printer for colors
Browse files Browse the repository at this point in the history
  • Loading branch information
leostera committed Dec 21, 2023
1 parent 83db5e6 commit d64f98e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions tty/color.ml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion tty/color.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d64f98e

Please sign in to comment.