diff --git a/src/core/CCFormat.ml b/src/core/CCFormat.ml index 3eb5f5a0..1ed6853d 100644 --- a/src/core/CCFormat.ml +++ b/src/core/CCFormat.ml @@ -264,6 +264,17 @@ let set_color_default = 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 buf = Buffer.create 64 in let fmt = Format.formatter_of_buffer buf in diff --git a/src/core/CCFormat.mli b/src/core/CCFormat.mli index dbc7ec2e..4f7ee00f 100644 --- a/src/core/CCFormat.mli +++ b/src/core/CCFormat.mli @@ -115,6 +115,18 @@ val set_color_default : bool -> unit (stdout, stderr) if [b = true] as well as on {!sprintf} formatters; 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} *) val output : t -> 'a printer -> 'a -> unit