mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 03:35:30 -05:00
add CCFormat.{with_color, with_colorf}
This commit is contained in:
parent
7d8369ab83
commit
e2848675f7
2 changed files with 23 additions and 0 deletions
|
|
@ -264,6 +264,17 @@ let set_color_default =
|
||||||
s
|
s
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
let with_color s pp out x =
|
||||||
|
Format.pp_open_tag out s;
|
||||||
|
pp out x;
|
||||||
|
Format.pp_close_tag out ()
|
||||||
|
|
||||||
|
let with_colorf s out fmt =
|
||||||
|
Format.pp_open_tag out s;
|
||||||
|
Format.kfprintf
|
||||||
|
(fun out -> Format.pp_close_tag out ())
|
||||||
|
out fmt
|
||||||
|
|
||||||
let sprintf format =
|
let sprintf format =
|
||||||
let buf = Buffer.create 64 in
|
let buf = Buffer.create 64 in
|
||||||
let fmt = Format.formatter_of_buffer buf in
|
let fmt = Format.formatter_of_buffer buf in
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,18 @@ val set_color_default : bool -> unit
|
||||||
(stdout, stderr) if [b = true] as well as on {!sprintf} formatters;
|
(stdout, stderr) if [b = true] as well as on {!sprintf} formatters;
|
||||||
it disables the color handling if [b = false]. *)
|
it disables the color handling if [b = false]. *)
|
||||||
|
|
||||||
|
val with_color : string -> 'a printer -> 'a printer
|
||||||
|
(** [with_color "Blue" pp] behaves like the printer [pp], but with the given
|
||||||
|
style.
|
||||||
|
{b status: experimental}
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val with_colorf : string -> t -> ('a, t, unit, unit) format4 -> 'a
|
||||||
|
(** [with_colorf "Blue" out "%s %d" "yolo" 42] will behave like {!Format.fprintf},
|
||||||
|
but wrapping the content with the given style
|
||||||
|
{b status: experimental}
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
(** {2 IO} *)
|
(** {2 IO} *)
|
||||||
|
|
||||||
val output : t -> 'a printer -> 'a -> unit
|
val output : t -> 'a printer -> 'a -> unit
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue