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 committed Apr 7, 2018
1 parent fa685d5 commit ea6a1ae
Show file tree
Hide file tree
Showing 2 changed files with 9 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
7 changes: 5 additions & 2 deletions src/unix/Lwt_fmt.mli
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ val make_formatter :
functions to update the underlying channel.
*)

val get_formatter : formatter -> Format.formatter
(** [get_formatter fmt] returns the underlying {!Format.formatter}. *)

(** {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 ea6a1ae

Please sign in to comment.