module Pretty_utils:sig..end
val sfprintf : ('a, Format.formatter, unit, string) Pervasives.format4 -> 'aval ksfprintf : (string -> 'b) -> ('a, Format.formatter, unit, 'b) Pervasives.format4 -> 'aval to_string : ?margin:int -> (Format.formatter -> 'a -> unit) -> 'a -> stringmargin is the
maximal width of the box before a line-break is inserted.
See Format.set_marginval pp_print_string_fill : Format.formatter -> string -> unitval escape_underscores : string -> stringtypesformat =(unit, Format.formatter, unit) Pervasives.format
type'aformatter =Format.formatter -> 'a -> unit
type('a, 'b)formatter2 =Format.formatter -> 'a -> 'b -> unit
val pp_list : ?pre:sformat ->
?sep:sformat ->
?last:sformat ->
?suf:sformat ->
?empty:sformat ->
'a formatter -> 'a list formatteremptyval pp_array : ?pre:sformat ->
?sep:sformat ->
?suf:sformat ->
?empty:sformat ->
(int, 'a) formatter2 -> 'a array formatteremptyval pp_iter : ?pre:sformat ->
?sep:sformat ->
?suf:sformat ->
(('a -> unit) -> 'b -> unit) ->
'a formatter -> 'b formatterpre (resp. suf) is output before (resp. after) the iterator
is started (resp. has ended). The optional argument sep is output between
two calls to the 'a formatter. Default: open a box for pre, close
a box for suf, nothing for sep.val pp_iter2 : ?pre:sformat ->
?sep:sformat ->
?suf:sformat ->
?between:sformat ->
(('key -> 'v -> unit) -> 'a -> unit) ->
'key formatter ->
'v formatter -> 'a formatterpre (resp. suf) is output before (resp. after) the iterator
is started (resp. has ended). The optional argument sep is output between
two calls to the 'a formatter. The optional argument between is
output between the key and the value. Default: open a box for pre, close
a box for suf, nothing for sep, break-space for between.val pp_opt : ?pre:sformat ->
?suf:sformat ->
?none:sformat ->
'a formatter -> 'a option formatter" and "@"
respectively. If the value is None, pretty-print using none.noneval pp_cond : ?pr_false:sformat ->
bool -> sformat formatterpp_cond cond f s pretty-prints s if cond is true and the optional
pr_false, which defaults to nothing, otherwiseval pp_pair : ?pre:sformat ->
?sep:sformat ->
?suf:sformat ->
'a formatter ->
'b formatter -> ('a * 'b) formatterpp_pair ?pre ?sep ?suf pp_a pp_b (a,b) pretty prints the pair (a,b),
using the pretty printers pp_a and pp_b, with optional
prefix/separator/suffix, whose default values are:val pp_flowlist : ?left:sformat ->
?sep:sformat ->
?right:sformat ->
'a formatter -> 'a list formatter
val pp_blocklist : ?left:sformat ->
?right:sformat ->
'a formatter -> 'a list formatter
val pp_open_block : Format.formatter -> ('a, Format.formatter, unit) Pervasives.format -> 'a
val pp_close_block : Format.formatter -> ('a, Format.formatter, unit) Pervasives.format -> 'a
val pp_trail : 'a formatter -> 'a formattertypealign =[ `Center | `Left | `Right ]
val pp_items : ?align:align ->
?margin:int ->
?min:int ->
?max:int ->
title:('a -> string) ->
iter:(('a -> unit) -> unit) ->
?pp_title:string formatter ->
pp_item:(string formatter -> 'a formatter) ->
Format.formatter -> unit
The collection of 'a to print is provided by iterator ~iter which
is called twice: one for computing the maximal size of titles,
obtained via function ~title for each item. The second pass
pretty-print each item using ~pp_item pp where the passed pp printer
can be used to pretty-print titles with alignment.
A typical usage for printing values, a list of (string*int) items:
pp_items
~title:(fun (a,_) -> a)
~iter:(fun f -> List.iter f values)
~pp_title:(fun fmt a -> Format.fprintf fmt "%s:" a)
~pp_item:(fun pp fmt (a,n) -> Format.fprintf fmt "%a %d@\n" pp a n)
fmt
Alignment of titles can be centered, right or left justified. This is rendered by adding spaces around each title. A min and max size can also be specified and a margin can be added to all title sizes. Titles will be truncated if necessary.
The pretty-printer for titles will render each (possibly truncated) title
with ~pp_title. Surrounding spaces are not printed via ~pp_title.
The (optional) parameters have the following meaning:
?align alignment mode (default is `Center)?margin is added to text size (default 0)?min minimum size (~margin included, default 0)?max maximum size (~margin included, default 80)~title returns the title for each element (only size is relevant)~iter iterate over the elements to be printed?pp_title pretty-printer used to the (possibly truncated) title
(default is Format.pp_print_string)~pp_item pretty-printer to print each element.Pretty_utils.marger,
Pretty_utils.pp_margin and Pretty_utils.add_margin below.type marger
pp_items).val marger : unit -> margerval add_margin : marger -> ?margin:int -> ?min:int -> ?max:int -> string -> unit?margin is added to text size (default 0)?min minimum size (~margin included, default 0)?max maximum size (~margin included, default 80)val pp_margin : ?align:align ->
?pp:string formatter ->
marger -> string formatter?align alignment mode (default is `Center)?pp pretty-printer used to the (possibly truncated) title
(default is Format.pp_print_string) begin
(* first, collect title margins *)
let m = marger () in
List.iter (fun (a,_) -> add_margin m ~margins:2 a) data ;
(* second, print aligned data *)
List.iter
(fun (a,d) -> Format.printf "[%a] %s@\n" (pp_margin m) a d)
data ;
end