From 2c5cda7e3dd858e6a228b3921a648c067a16bed5 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 9 Mar 2018 11:27:11 -0600 Subject: [PATCH] add `?margin` parameter to `CCFormat.ksprintf` --- src/core/CCFormat.ml | 3 ++- src/core/CCFormat.mli | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/CCFormat.ml b/src/core/CCFormat.ml index d01f3ad9..a9359cb6 100644 --- a/src/core/CCFormat.ml +++ b/src/core/CCFormat.ml @@ -383,10 +383,11 @@ let fprintf_dyn_color ~colors out fmt = assert_equal "yolo" (sprintf_no_color "@{yolo@}"); *) -let ksprintf ~f fmt = +let ksprintf ?margin ~f fmt = let buf = Buffer.create 32 in let out = Format.formatter_of_buffer buf in if !color_enabled then set_color_tag_handling out; + begin match margin with None -> () | Some m -> pp_set_margin out m end; Format.kfprintf (fun _ -> Format.pp_print_flush out (); f (Buffer.contents buf)) out fmt diff --git a/src/core/CCFormat.mli b/src/core/CCFormat.mli index 8b2e5ffd..f54c46d0 100644 --- a/src/core/CCFormat.mli +++ b/src/core/CCFormat.mli @@ -273,11 +273,13 @@ val fprintf_dyn_color : colors:bool -> t -> ('a, t, unit ) format -> 'a @since 0.21 *) val ksprintf : + ?margin:int -> f:(string -> 'b) -> ('a, Format.formatter, unit, 'b) format4 -> 'a (** [ksprintf fmt ~f] formats using [fmt], in a way similar to {!sprintf}, and then calls [f] on the resulting string. + @param margin set margin (since NEXT_RELEASE) @since 0.14 *) val to_file : string -> ('a, t, unit, unit) format4 -> 'a