add ?margin parameter to CCFormat.ksprintf

This commit is contained in:
Simon Cruanes 2018-03-09 11:27:11 -06:00
parent c578dd9583
commit 2c5cda7e3d
2 changed files with 4 additions and 1 deletions

View file

@ -383,10 +383,11 @@ let fprintf_dyn_color ~colors out fmt =
assert_equal "yolo" (sprintf_no_color "@{<red>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

View file

@ -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