Module B0_std.Fmt
Textual formatters.
Helpers for dealing with Format
.
Standard outputs and formatters
val stdout : Stdlib.Format.formatter
stdout
outputs to standard output.
val stderr : Stdlib.Format.formatter
stderr
outputs to standard error.
val flush : Stdlib.Format.formatter -> unit
flush
isFormat
.pp_print_flush.
Formatting
val pf : Stdlib.Format.formatter -> ('a, Stdlib.Format.formatter, unit) Stdlib.format -> 'a
pf
isFormat
.fprintf.
val pr : ('a, Stdlib.Format.formatter, unit) Stdlib.format -> 'a
pf
isFormat
.printf.
val epr : ('a, Stdlib.Format.formatter, unit) Stdlib.format -> 'a
epr
isFormat
.eprintf.
val str : ('a, Stdlib.Format.formatter, unit, string) Stdlib.format4 -> 'a
str is
Format
.asprintf.
val kpf : (Stdlib.Format.formatter -> 'a) -> Stdlib.Format.formatter -> ('b, Stdlib.Format.formatter, unit, 'a) Stdlib.format4 -> 'b
kpf
isFormat
.kfprintf.
val kstr : (string -> 'a) -> ('b, Stdlib.Format.formatter, unit, 'a) Stdlib.format4 -> 'b
kstr is
Format
.kasprintf.
val failwith : ('b, Stdlib.Format.formatter, unit, 'a) Stdlib.format4 -> 'b
failwith fmt ...
iskstr (fun s -> failwith s) fmt ...
val failwith_notrace : ('b, Stdlib.Format.formatter, unit, 'a) Stdlib.format4 -> 'b
failwith_notrace
is likent
butFailure
is raised withraise_notrace
.
val invalid_arg : ('b, Stdlib.Format.formatter, unit, 'a) Stdlib.format4 -> 'b
invalid_arg fmt ...
iskstr (fun s -> invalid_arg s) fmt ...
val error : ('b, Stdlib.Format.formatter, unit, ('a, string) Stdlib.result) Stdlib.format4 -> 'b
error fmt ...
iskstr (fun s -> Error s) fmt ...
Formatters
type 'a t
= Stdlib.Format.formatter -> 'a -> unit
The type for formatter of values of type
'a
.
val nop : 'a t
nop
formats nothing.
val unit : (unit, Stdlib.Format.formatter, unit) Stdlib.Pervasives.format -> unit t
unit fmt
formats a unit value with the formatfmt
.
val cut : unit t
cut
isFormat
.pp_print_cut.
val sp : unit t
sp
isFormat
.pp_print_space.
val comma : unit t
comma
isunit ",@ "
.
Base type formatters
val bool : bool t
bool
isFormat
.pp_print_bool.
val int : int t
int
isFormat
.pp_print_int.
val int32 : int32 t
int32
ispf ppf "%ld"
.
val int64 : int64 t
int64
ispf ppf "%Ld"
.
val float : float t
float
ispf ppf "%g"
.
val char : char t
char
isFormat
.pp_print_char.
val string : string t
string
isFormat
.pp_print_string.
val elided_string : max:int -> string t
elieded_string ~max
formats a string using at mostmax
characters, eliding it if it is too long with three consecutive dots which do count towardsmax
.
val pair : ?sep:unit t -> 'a t -> 'b t -> ('a * 'b) t
pair ~sep pp_fst pp_snd
formats a pair. The first and second projection are formatted usingpp_fst
andpp_snd
and are separated bysep
(defaults tocut
).
val list : ?empty:unit t -> ?sep:unit t -> 'a t -> 'a list t
list ~sep pp_v
formats list elements. Each element of the list is formatted in order withpp_v
. Elements are separated bysep
(defaults tocut
). If the list is empty, this isempty
(defaults tonop
).
val array : ?empty:unit t -> ?sep:unit t -> 'a t -> 'a array t
array ~sep pp_v
formats array elements. Each element of the array is formatted in in order withpp_v
. Elements are seperated bysep
(defaults tocut
). If the array is empty this isempty
(defauls tonop
).
val option : ?none:unit t -> 'a t -> 'a option t
option ~none pp_v
formats an option. TheSome
case usespp_v
andNone
usesnone
(defaults tonop
).
val none : unit t
none
isunit "<none>"
.
val iter : ?sep:unit t -> (('a -> unit) -> 'b -> unit) -> 'a t -> 'b t
iter ~sep iter pp_elt
formats the iterations ofiter
over a value usingpp_elt
. Iterations are separated bysep
(defaults tocut
).
val iter_bindings : ?sep:unit t -> (('a -> 'b -> unit) -> 'c -> unit) -> ('a * 'b) t -> 'c t
iter_bindings ~sep iter pp_binding
formats the iterations ofiter
over a value usingpp_binding
. Iterations are separated bysep
(defaults tocut
).
val text : string t
text
isFormat
.pp_print_text.
val lines : string t
lines
formats lines by replacing newlines ('\n'
) in the string with calls toFormat
.pp_force_newline.
val exn : exn t
exn
formats an exception.
val exn_backtrace : (exn * Stdlib.Printexc.raw_backtrace) t
exn_backtrace
formats an exception backtrace.
Boxes
val box : ?indent:int -> 'a t -> 'a t
box ~indent pp ppf
wrapspp
in a horizontal or vertical box. Break hints that lead to a new line addindent
to the current indentation (defaults to0
).
val hbox : 'a t -> 'a t
hbox
is likebox
but is a horizontal box: the line is not split in this box (but may be in sub-boxes).
Quoting
Brackets
ANSI TTY styling
val set_tty_styling_cap : Tty.cap -> unit
set_tty_styling_cap c
sets the global styling capabilities toc
. Affects the output oftty_str
and ANSI TTY styling.
val tty_styling_cap : unit -> Tty.cap
tty_styling_cap ()
is the global styling capability.
val tty_string : Tty.style list -> string t
tty_string styles ppf s
printss
onppf
according tostyles
and the value oftty_styling_cap
.
val tty : Tty.style list -> 'a t -> 'a t
tty styles pp_v ppf v
printsv
withpp_v
onppf
according tostyles
and the value oftty_styling_cap
.
Alternatives
Fields
Magnitudes
val si_size : scale:int -> string -> int t
si_size ~scale unit
formats a non negative integer representing unitunit
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 usingu
.scale
indicates the scale 10scale * 3 an integer represents, for example-1
for munit
(10-3),0
forunit
(100),1
forkunit
(103); it must be in the range [-8
;8
] orInvalid_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 t
byte_size
issi_size ~scale:0 "B"
.
val uint64_ns_span : int64 t
uint64_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
).