Skip to content

Commit

Permalink
Make the API a bit more regular reguarding formatters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Drup authored and aantron committed Apr 9, 2018
1 parent 2b099fc commit e5295cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/unix/Lwt_fmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ let flush ppft = Format.pp_print_flush ppft.fmt () ; ppft.commit ()

let make_formatter ~commit ~fmt () = { commit ; fmt }

let get_formatter x = x.fmt

(** Stream formatter *)

type order =
Expand Down Expand Up @@ -80,9 +82,9 @@ let of_channel oc =
(** Printing functions *)

let kfprintf k ppft fmt =
Format.kfprintf (fun ppf -> k ppf @@ ppft.commit ()) ppft.fmt fmt
Format.kfprintf (fun _ppf -> k ppft @@ ppft.commit ()) ppft.fmt fmt
let ikfprintf k ppft fmt =
Format.ikfprintf (fun ppf -> k ppf @@ Lwt.return_unit) ppft.fmt fmt
Format.ikfprintf (fun _ppf -> k ppft @@ Lwt.return_unit) ppft.fmt fmt

let fprintf ppft fmt =
kfprintf (fun _ t -> t) ppft fmt
Expand Down
10 changes: 8 additions & 2 deletions src/unix/Lwt_fmt.mli
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,24 @@ val make_formatter :
functions to update the underlying channel.
*)

val get_formatter : formatter -> Format.formatter
(** [get_formatter fmt] returns the underlying {!Format.formatter}.
To access the underlying formatter during printing, it is
recommended to use [%t] and [%a].
*)

(** {2 Printing} *)

val fprintf : formatter -> ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a

val kfprintf :
(Format.formatter -> unit Lwt.t -> 'a) ->
(formatter -> unit Lwt.t -> 'a) ->
formatter -> ('b, Format.formatter, unit, 'a) format4 -> 'b

val ifprintf : formatter -> ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a

val ikfprintf :
(Format.formatter -> unit Lwt.t -> 'a) ->
(formatter -> unit Lwt.t -> 'a) ->
formatter -> ('b, Format.formatter, unit, 'a) format4 -> 'b

val flush : formatter -> unit Lwt.t
Expand Down

0 comments on commit e5295cb

Please sign in to comment.