mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
add CCFormat.of_chan
This commit is contained in:
parent
719d048f57
commit
ae6d81a9a4
2 changed files with 22 additions and 0 deletions
|
|
@ -135,6 +135,18 @@ let fprintf = Format.fprintf
|
|||
let stdout = Format.std_formatter
|
||||
let stderr = Format.err_formatter
|
||||
|
||||
let of_chan = Format.formatter_of_out_channel
|
||||
|
||||
let with_out_chan oc f =
|
||||
let fmt = of_chan oc in
|
||||
try
|
||||
let x = f fmt in
|
||||
Format.pp_print_flush fmt ();
|
||||
x
|
||||
with e ->
|
||||
Format.pp_print_flush fmt ();
|
||||
raise e
|
||||
|
||||
let tee a b =
|
||||
let fa = Format.pp_get_formatter_out_functions a () in
|
||||
let fb = Format.pp_get_formatter_out_functions b () in
|
||||
|
|
|
|||
|
|
@ -184,6 +184,16 @@ val with_color_sf : string -> ('a, t, unit, string) format4 -> 'a
|
|||
val output : t -> 'a printer -> 'a -> unit
|
||||
val to_string : 'a printer -> 'a -> string
|
||||
|
||||
val of_chan : out_channel -> t
|
||||
(** Alias to {!Format.formatter_of_out_channel}
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val with_out_chan : out_channel -> (t -> 'a) -> 'a
|
||||
(** [with_out_chan oc f] turns [oc] into a formatter [fmt], and call [f fmt].
|
||||
Behaves like [f fmt] from then on, but whether the call to [f] fails
|
||||
or returns, [fmt] is flushed before the call terminates.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val stdout : t
|
||||
val stderr : t
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue