Module Bos_setup.Fmt
include module type of struct include Fmt end
Standard outputs
val stdout : Stdlib.Format.formatterstdout is the standard output formatter.
val stderr : Stdlib.Format.formatterstderr is the standard error formatter.
Formatting
val pf :
Stdlib.Format.formatter ->
('a, Stdlib.Format.formatter, unit) Stdlib.format ->
'apf is Format.fprintf.
val pr : ('a, Stdlib.Format.formatter, unit) Stdlib.format -> 'apr is pf stdout.
val epr : ('a, Stdlib.Format.formatter, unit) Stdlib.format -> 'aepr is pf stderr.
val str : ('a, Stdlib.Format.formatter, unit, string) Stdlib.format4 -> 'astr is Format.asprintf.
Note. When using str utf_8 and style_renderer are always respectively set to true and `None. See also str_like.
val kpf :
(Stdlib.Format.formatter -> 'a) ->
Stdlib.Format.formatter ->
('b, Stdlib.Format.formatter, unit, 'a) Stdlib.format4 ->
'bkpf is Format.kfprintf.
val kstr :
(string -> 'a) ->
('b, Stdlib.Format.formatter, unit, 'a) Stdlib.format4 ->
'bkstr is like str but continuation based.
val str_like :
Stdlib.Format.formatter ->
('a, Stdlib.Format.formatter, unit, string) Stdlib.format4 ->
'astr_like ppf is like str except its utf_8 and style_renderer settings are those of ppf.
val with_buffer :
?like:Stdlib.Format.formatter ->
Stdlib.Buffer.t ->
Stdlib.Format.formatterwith_buffer ~like b is a formatter whose utf_8 and style_renderer settings are copied from those of like (if provided).
val failwith : ('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 -> 'afailwith is kstr failwith, raises Stdlib.Failure with a pretty-printed string argument.
val failwith_notrace :
('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 ->
'afailwith_notrace is like failwith but raises with raise_notrace.
val invalid_arg : ('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 -> 'ainvalid_arg is kstr invalid_arg, raises Stdlib.Invalid_argument with a pretty-printed string argument.
val error :
('b, Stdlib.Format.formatter, unit, ('a, string) Stdlib.result)
Stdlib.format4 ->
'berror fmt ... is kstr (fun s -> Error s) fmt ...
val error_msg :
('b, Stdlib.Format.formatter, unit, ('a, [> `Msg of string ]) Stdlib.result)
Stdlib.format4 ->
'berror_msg fmt ... is kstr (fun s -> Error (`Msg s)) fmt ...
Formatters
type 'a t = Stdlib.Format.formatter -> 'a -> unitThe type for formatters of values of type 'a.
val flush : 'a Bos_setup.Fmt.tflush has the effect of Format.pp_print_flush
val nop : 'a Bos_setup.Fmt.tnop formats nothing.
val any :
(unit, Stdlib.Format.formatter, unit) Stdlib.format ->
'a Bos_setup.Fmt.tany fmt ppf v formats any value with the constant format fmt.
val using : ('a -> 'b) -> 'b Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tusing f pp ppf v ppf ppf (f v).
val const : 'a Bos_setup.Fmt.t -> 'a -> 'b Bos_setup.Fmt.tconst pp_v v always formats v using pp_v.
val if' : bool -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tif' bool pp is pp if bool is true and nop otherwise.
val fmt :
('a, Stdlib.Format.formatter, unit) Stdlib.format ->
Stdlib.Format.formatter ->
'afmt fmt ppf is pf ppf fmt. If fmt is used with a single non-constant formatting directive, generates a value of type t.
Separators
val cut : 'a Bos_setup.Fmt.tcut has the effect of Format.pp_print_cut.
val sp : 'a Bos_setup.Fmt.tsp has the effect of Format.pp_print_space.
val sps : int -> 'a Bos_setup.Fmt.tsps n has the effect of Format.pp_print_break n 0.
val comma : 'a Bos_setup.Fmt.tcomma is Fmt.any ",@ ".
val semi : 'a Bos_setup.Fmt.tsemi is Fmt.any ";@ ".
Sequencing
val append : 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tappend pp_v0 pp_v1 ppf v is pp_v0 ppf v; pp_v1 ppf v.
val (++) : 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.t( ++ ) is append.
val concat :
?sep:unit Bos_setup.Fmt.t ->
'a Bos_setup.Fmt.t list ->
'a Bos_setup.Fmt.tconcat ~sep pps formats a value using the formaters pps and separting each format with sep (defaults to cut).
val iter :
?sep:unit Bos_setup.Fmt.t ->
(('a -> unit) -> 'b -> unit) ->
'a Bos_setup.Fmt.t ->
'b Bos_setup.Fmt.titer ~sep iter pp_elt formats the iterations of iter over a value using pp_elt. Iterations are separated by sep (defaults to cut).
val iter_bindings :
?sep:unit Bos_setup.Fmt.t ->
(('a -> 'b -> unit) -> 'c -> unit) ->
('a * 'b) Bos_setup.Fmt.t ->
'c Bos_setup.Fmt.titer_bindings ~sep iter pp_binding formats the iterations of iter over a value using pp_binding. Iterations are separated by sep (defaults to cut).
Boxes
val box : ?indent:int -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tbox ~indent pp ppf wraps pp in a pretty-printing box. The box tries to print as much as possible on every line, while emphasizing the box structure (see Format.pp_open_box). Break hints that lead to a new line add indent to the current indentation (defaults to 0).
val hbox : 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.thbox is like box but is a horizontal box: the line is not split in this box (but may be in sub-boxes). See Format.pp_open_hbox.
val vbox : ?indent:int -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tvbox is like box but is a vertical box: every break hint leads to a new line which adds indent to the current indentation (defaults to 0). See Format.pp_open_vbox.
val hvbox : ?indent:int -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.thvbox is like hbox if it fits on a single line, or like vbox otherwise. See Format.pp_open_hvbox.
val hovbox : ?indent:int -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.thovbox is a condensed box. See Format.pp_open_hovbox.
Brackets
val parens : 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tparens pp_v ppf is pf "@[<1>(%a)@]" pp_v.
val brackets : 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tbrackets pp_v ppf is pf "@[<1>[%a]@]" pp_v.
val braces : 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tbraces pp_v ppf is pf "@[<1>{%a}@]" pp_v.
val quote : ?mark:string -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tquote ~mark pp_v ppf is pf "@[<1>@<1>%s%a@<1>%s@]" mark pp_v mark, mark defaults to "\"", it is always counted as spanning as single column (this allows for UTF-8 encoded marks).
Records
id is Fun.id.
val field :
?label:string Bos_setup.Fmt.t ->
?sep:unit Bos_setup.Fmt.t ->
string ->
('b -> 'a) ->
'a Bos_setup.Fmt.t ->
'b Bos_setup.Fmt.tfield ~label ~sep l prj pp_v pretty prints a labelled field value as pf "@[<1>%a%a%a@]" label l sep () (using prj pp_v). label defaults to styled `Yellow string and sep to any ":@ ".
val record :
?sep:unit Bos_setup.Fmt.t ->
'a Bos_setup.Fmt.t list ->
'a Bos_setup.Fmt.trecord ~sep fields pretty-prints a value using the concatenation of fields, separated by sep (defaults to cut) and framed in a vertical box.
Stdlib types
Formatters for structures give full control to the client over the formatting process and do not wrap the formatted structures with boxes. Use the Dump module to quickly format values for inspection.
val bool : bool Bos_setup.Fmt.tbool is Format.pp_print_bool.
val int : int Bos_setup.Fmt.tint ppf is pf ppf "%d".
val nativeint : nativeint Bos_setup.Fmt.tnativeint ppf is pf ppf "%nd".
val int32 : int32 Bos_setup.Fmt.tint32 ppf is pf ppf "%ld".
val int64 : int64 Bos_setup.Fmt.tint64 ppf is pf ppf "%Ld".
val uint : int Bos_setup.Fmt.tuint ppf is pf ppf "%u".
val unativeint : nativeint Bos_setup.Fmt.tunativeint ppf is pf ppf "%nu".
val uint32 : int32 Bos_setup.Fmt.tuint32 ppf is pf ppf "%lu".
val uint64 : int64 Bos_setup.Fmt.tuint64 ppf is pf ppf "%Lu".
val float : float Bos_setup.Fmt.tfloat ppf is pf ppf "%g".
val float_dfrac : int -> float Bos_setup.Fmt.tfloat_dfrac d rounds the float to the dth decimal fractional digit and formats the result with "%g". Ties are rounded towards positive infinity. The result is only defined for 0 <= d <= 16.
val float_dsig : int -> float Bos_setup.Fmt.tfloat_dsig d rounds the normalized decimal significand of the float to the dth decimal fractional digit and formats the result with "%g". Ties are rounded towards positive infinity. The result is NaN on infinities and only defined for 0 <= d <= 16.
Warning. The current implementation overflows on large d and floats.
val char : char Bos_setup.Fmt.tchar is Format.pp_print_char.
val string : string Bos_setup.Fmt.tstring is Format.pp_print_string.
val buffer : Stdlib.Buffer.t Bos_setup.Fmt.tbuffer formats a Buffer.t value's current contents.
val exn : exn Bos_setup.Fmt.texn formats an exception.
val exn_backtrace : (exn * Stdlib.Printexc.raw_backtrace) Bos_setup.Fmt.texn_backtrace formats an exception backtrace.
val pair :
?sep:unit Bos_setup.Fmt.t ->
'a Bos_setup.Fmt.t ->
'b Bos_setup.Fmt.t ->
('a * 'b) Bos_setup.Fmt.tpair ~sep pp_fst pp_snd formats a pair. The first and second projection are formatted using pp_fst and pp_snd and are separated by sep (defaults to cut).
val option :
?none:unit Bos_setup.Fmt.t ->
'a Bos_setup.Fmt.t ->
'a option Bos_setup.Fmt.toption ~none pp_v formats an optional value. The Some case uses pp_v and None uses none (defaults to nop).
val result :
ok:'a Bos_setup.Fmt.t ->
error:'b Bos_setup.Fmt.t ->
('a, 'b) Stdlib.result Bos_setup.Fmt.tresult ~ok ~error formats a result value using ok for the Ok case and error for the Error case.
val list :
?sep:unit Bos_setup.Fmt.t ->
'a Bos_setup.Fmt.t ->
'a list Bos_setup.Fmt.tval array :
?sep:unit Bos_setup.Fmt.t ->
'a Bos_setup.Fmt.t ->
'a array Bos_setup.Fmt.tval seq :
?sep:unit Bos_setup.Fmt.t ->
'a Bos_setup.Fmt.t ->
'a Stdlib.Seq.t Bos_setup.Fmt.tval hashtbl :
?sep:unit Bos_setup.Fmt.t ->
('a * 'b) Bos_setup.Fmt.t ->
('a, 'b) Stdlib.Hashtbl.t Bos_setup.Fmt.thashtbl ~sep pp_binding formats the bindings of a hash table. Each binding is formatted with pp_binding and bindings are separated by sep (defaults to cut). If the hash table has multiple bindings for a given key, all bindings are formatted, with the most recent binding first. If the hash table is empty, this is nop.
val queue :
?sep:unit Bos_setup.Fmt.t ->
'a Bos_setup.Fmt.t ->
'a Stdlib.Queue.t Bos_setup.Fmt.tval stack :
?sep:unit Bos_setup.Fmt.t ->
'a Bos_setup.Fmt.t ->
'a Stdlib.Stack.t Bos_setup.Fmt.tmodule Dump = Fmt.DumpFormatters for inspecting OCaml values.
Magnitudes
val si_size : scale:int -> string -> int Bos_setup.Fmt.tsi_size ~scale unit formats a non negative integer representing unit unit at scale 10scale * 3, depending on its magnitude, using power of 3 SI prefixes (i.e. all of them except deca, hector, deci and centi). Only US-ASCII characters are used, µ (10-6) is written using u.
scale indicates the scale 10scale * 3 an integer represents, for example -1 for munit (10-3), 0 for unit (100), 1 for kunit (103); it must be in the range [-8;8] or Invalid_argument is raised.
Except at the maximal yotta scale always tries to show three digits of data with trailing fractional zeros omited. Rounds towards positive infinity (over approximates).
val byte_size : int Bos_setup.Fmt.tbyte_size is si_size ~scale:0 "B".
val bi_byte_size : int Bos_setup.Fmt.tbi_byte_size formats a byte size according to its magnitude using binary prefixes up to pebi bytes (215).
val uint64_ns_span : int64 Bos_setup.Fmt.tuint64_ns_span formats an unsigned nanosecond time span according to its magnitude using SI prefixes on seconds and accepted non-SI units. Years are counted in Julian years (365.25 SI-accepted days) as defined by the International Astronomical Union (IAU). Only US-ASCII characters are used (us is used for µs).
Binary data
The type for random addressable, sized sequences. Each (n, f) represents the sequence f 0, ..., f (n - 1).
val on_bytes : char Bos_setup.Fmt.vec Bos_setup.Fmt.t -> bytes Bos_setup.Fmt.ton_bytes pp is pp adapted to format (entire) bytes.
val on_string :
char Bos_setup.Fmt.vec Bos_setup.Fmt.t ->
string Bos_setup.Fmt.ton_string pp is pp adapted to format (entire) strings.
val ascii :
?w:int ->
?subst:unit Bos_setup.Fmt.t ->
unit ->
char Bos_setup.Fmt.vec Bos_setup.Fmt.tascii ~w ~subst () formats character sequences by printing characters in the printable US-ASCII range ([0x20];[0x7E]) as is, and replacing the rest with subst (defaults to fmt "."). w causes the output to be right padded to the size of formatting at least w sequence elements (defaults to 0).
val octets :
?w:int ->
?sep:unit Bos_setup.Fmt.t ->
unit ->
char Bos_setup.Fmt.vec Bos_setup.Fmt.toctets ~w ~sep () formats character sequences as hexadecimal digits. It prints groups of successive characters of unspecified length together, separated by sep (defaults to sp). w causes the output to be right padded to the size of formatting at least w sequence elements (defaults to 0).
val addresses :
?addr:int Bos_setup.Fmt.t ->
?w:int ->
'a Bos_setup.Fmt.vec Bos_setup.Fmt.t ->
'a Bos_setup.Fmt.vec Bos_setup.Fmt.taddresses pp formats sequences by applying pp to consecutive subsequences of length w (defaults to 16). addr formats subsequence offsets (defaults to an unspecified hexadecimal format).
val hex : ?w:int -> unit -> char Bos_setup.Fmt.vec Bos_setup.Fmt.thex ~w () formats character sequences as traditional hex dumps, matching the output of xxd and forcing line breaks after every w characters (defaults to 16).
Words, paragraphs, text and lines
Note. These functions only work on US-ASCII strings and/or with newlines ('\n'). If you are dealing with UTF-8 strings or different kinds of line endings you should use the pretty-printers from Uuseg_string.
White space. White space is one of the following US-ASCII characters: space ' ' (0x20), tab '\t' (0x09), newline '\n' (0x0A), vertical tab (0x0B), form feed (0x0C), carriage return '\r' (0x0D).
val words : string Bos_setup.Fmt.twords formats words by suppressing initial and trailing white space and replacing consecutive white space with a single Format.pp_print_space.
val paragraphs : string Bos_setup.Fmt.tparagraphs formats paragraphs by suppressing initial and trailing spaces and newlines, replacing blank lines (a line made only of white space) by a two Format.pp_force_newline and remaining consecutive white space with a single Format.pp_print_space.
val text : string Bos_setup.Fmt.ttext formats text by respectively replacing spaces and newlines in the string with Format.pp_print_space and Format.pp_force_newline.
val lines : string Bos_setup.Fmt.tlines formats lines by replacing newlines ('\n') in the string with calls to Format.pp_force_newline.
val truncated : max:int -> string Bos_setup.Fmt.ttruncated ~max formats a string using at most max characters. If the string doesn't fit, it is truncated and ended with three consecutive dots which do count towards max.
val text_loc : ((int * int) * (int * int)) Bos_setup.Fmt.ttext_loc formats a line-column text range according to GNU conventions.
HCI fragments
val one_of :
?empty:unit Bos_setup.Fmt.t ->
'a Bos_setup.Fmt.t ->
'a list Bos_setup.Fmt.tone_of ~empty pp_v ppf l formats according to the length of l
0, formatsempty(defaults tonop).1, formats the element withpp_v.2, formats"either %a or %a"with the list elementsn, formats"one of %a, ... or %a"with the list elements
val did_you_mean :
?pre:unit Bos_setup.Fmt.t ->
?post:unit Bos_setup.Fmt.t ->
kind:string ->
'a Bos_setup.Fmt.t ->
('a * 'a list) Bos_setup.Fmt.tdid_you_mean ~pre kind ~post pp_v formats a faulty value v of kind kind and a list of hints that v could have been mistaken for.
pre defaults to unit "Unknown", post to nop they surround the faulty value before the "did you mean" part as follows "%a %s %a%a." pre () kind pp_v v post (). If hints is empty no "did you mean" part is printed.
Conditional UTF-8 formatting
Note. Since Format is not UTF-8 aware using UTF-8 output may derail the pretty printing process. Use the pretty-printers from Uuseg_string if you are serious about UTF-8 formatting.
val if_utf_8 : 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tif_utf_8 pp_u pp ppf v is:
pp_u ppf vifutf_8 ppfistrue.pp ppf votherwise.
val utf_8 : Stdlib.Format.formatter -> boolutf_8 ppf is true if UTF-8 output is enabled on ppf. If set_utf_8 hasn't been called on ppf this is true.
val set_utf_8 : Stdlib.Format.formatter -> bool -> unitset_utf_8 ppf b enables or disables conditional UTF-8 formatting on ppf.
Styled formatting
The type for colors.
type style = [ | `None| `Bold| `Faint| `Italic| `Underline| `Reverse| `Fg of [ Bos_setup.Fmt.color | `Hi of Bos_setup.Fmt.color ]| `Bg of [ Bos_setup.Fmt.color | `Hi of Bos_setup.Fmt.color ]| Bos_setup.Fmt.color
]The type for styles:
`Noneresets the styling.`Bold,`Faint,`Italic,`Underlineand`Reverseare display attributes.`Fg _is the foreground color or high-intensity color on`Hi _.`Bg _is the background color or high-intensity color on`Hi _.#coloris the foreground color, deprecated use`Fg #colorinstead.
val styled : Bos_setup.Fmt.style -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tstyled s pp formats like pp but styled with s.
Style rendering control
The type for style renderers.
`Ansi_tty, renders styles using ANSI escape sequences.`None, styled rendering has no effect.
val style_renderer : Stdlib.Format.formatter -> Bos_setup.Fmt.style_rendererstyle_renderer ppf is the style renderer used by ppf. If set_style_renderer has never been called on ppf this is `None.
val set_style_renderer :
Stdlib.Format.formatter ->
Bos_setup.Fmt.style_renderer ->
unitset_style_renderer ppf r sets the style renderer of ppf to r.
Converting with string value converters
val of_to_string : ('a -> string) -> 'a Bos_setup.Fmt.tof_to_string f ppf v is string ppf (f v).
val to_to_string : 'a Bos_setup.Fmt.t -> 'a -> stringto_to_string pp_v v is strf "%a" pp_v v.
Deprecated
val strf : ('a, Stdlib.Format.formatter, unit, string) Stdlib.format4 -> 'aval kstrf :
(string -> 'a) ->
('b, Stdlib.Format.formatter, unit, 'a) Stdlib.format4 ->
'bval strf_like :
Stdlib.Format.formatter ->
('a, Stdlib.Format.formatter, unit, string) Stdlib.format4 ->
'aval always :
(unit, Stdlib.Format.formatter, unit) Stdlib.format ->
'a Bos_setup.Fmt.tval unit :
(unit, Stdlib.Format.formatter, unit) Stdlib.format ->
unit Bos_setup.Fmt.tval prefix : unit Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tval suffix : unit Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.t -> 'a Bos_setup.Fmt.tval styled_unit :
Bos_setup.Fmt.style ->
(unit, Stdlib.Format.formatter, unit) Stdlib.format ->
unit Bos_setup.Fmt.tNaming conventions
Given a type ty use:
pp_tyfor a pretty printer that provides full control to the client and does not wrap the formatted value in an enclosing box. See these examples.pp_dump_tyfor a pretty printer that provides little control over the pretty-printing process, wraps the rendering in an enclosing box and tries as much as possible to respect the OCaml syntax. These pretty-printers should make it easy to inspect and understand values of the given type, they are mainly used for quick printf debugging and/or toplevel interaction. See these examples.
If you are in a situation where making a difference between dump_ty and pp_ty doesn't make sense then use pp_ty.
For a type ty that is the main type of the module (the "M.t" convention) drop the suffix, that is simply use M.pp and M.pp_dump.