module CCFormat:sig
..end
type'a
sequence =('a -> unit) -> unit
typet =
Format.formatter
type'a
printer =t -> 'a -> unit
val silent : 'a printer
val unit : unit printer
val int : int printer
val string : string printer
val bool : bool printer
val float3 : float printer
val float : float printer
val newline : unit printer
Format.pp_force_newline
)val substring : (string * int * int) printer
(s,i,len)
, where i
is the offset
in s
and len
the number of bytes in the substring.Invalid_argument
if the triple (s,i,len)
does not
describe a proper substring.val text : string printer
CCFormat.newline
.
See pp_print_text
on recent versions of OCaml.val char : char printer
val int32 : int32 printer
val int64 : int64 printer
val nativeint : nativeint printer
val flush : unit printer
Format.pp_print_flush
.val string_quoted : string printer
CCString.print
.val list : ?sep:unit printer -> 'a printer -> 'a list printer
val array : ?sep:unit printer ->
'a printer -> 'a array printer
val arrayi : ?sep:unit printer ->
(int * 'a) printer -> 'a array printer
val seq : ?sep:unit printer ->
'a printer -> 'a sequence printer
val opt : 'a printer -> 'a option printer
opt pp
prints options as follows:
Some x
will become "some foo" if pp x ---> "foo"
None
will become "none"sep
argument is only availableval pair : ?sep:unit printer ->
'a printer -> 'b printer -> ('a * 'b) printer
val triple : ?sep:unit printer ->
'a printer ->
'b printer -> 'c printer -> ('a * 'b * 'c) printer
val quad : ?sep:unit printer ->
'a printer ->
'b printer ->
'c printer ->
'd printer -> ('a * 'b * 'c * 'd) printer
val within : string -> string -> 'a printer -> 'a printer
within a b p
wraps p
inside the strings a
and b
. Convenient,
for instances, for brackets, parenthesis, quotes, etc.val map : ('a -> 'b) -> 'b printer -> 'a printer
val vbox : ?i:int -> 'a printer -> 'a printer
i
: level of indentation within the box (default 0)val hvbox : ?i:int -> 'a printer -> 'a printer
i
: level of indentation within the box (default 0)val hovbox : ?i:int -> 'a printer -> 'a printer
i
: level of indentation within the box (default 0)val hbox : 'a printer -> 'a printer
val return : ('a, 'b, 'c, 'a) Pervasives.format4 -> unit printer
return "some_format_string"
takes a argument-less format string
and returns a printer actionable by ()
.
Examples:return ",@ "
return "@{<Red>and then@}@,"
return "@[<v>a@ b@]"
val of_to_string : ('a -> string) -> 'a printer
of_to_string f
converts its input to a string using f
,
then prints the stringval const : 'a printer -> 'a -> unit printer
const pp x
is a unit printer that uses pp
on x
val some : 'a printer -> 'a option printer
some pp
will print options as follows:Some x
is printed using pp
on x
None
is not printed at allUse ANSI escape codes https://en.wikipedia.org/wiki/ANSI_escape_code to put some colors on the terminal.
This uses tags in format strings to specify the style. Current styles are the following:
Example:
set_color_default true;;
Format.printf
"what is your @{<White>favorite color@}? @{<blue>blue@}! No, @{<red>red@}! Ahhhhhhh@.";;
status: experimental
val set_color_tag_handling : t -> unit
val set_color_default : bool -> unit
set_color_default b
enables color handling on the standard formatters
(stdout, stderr) if b = true
as well as on CCFormat.sprintf
formatters;
it disables the color handling if b = false
.val with_color : string -> 'a printer -> 'a printer
with_color "Blue" pp
behaves like the printer pp
, but with the given
style.
status: experimentalval with_colorf : string -> t -> ('a, t, unit, unit) Pervasives.format4 -> 'a
with_colorf "Blue" out "%s %d" "yolo" 42
will behave like Format.fprintf
,
but wrapping the content with the given style
status: experimentalval with_color_sf : string -> ('a, t, unit, string) Pervasives.format4 -> 'a
with_color_sf "Blue" out "%s %d" "yolo" 42
will behave like
CCFormat.sprintf
, but wrapping the content with the given style
Example:
CCFormat.with_color_sf "red" "%a" CCFormat.Dump.(list int) [1;2;3] |> print_endline;;
status: experimentalval with_color_ksf : f:(string -> 'b) ->
string -> ('a, t, unit, 'b) Pervasives.format4 -> 'a
with_color_ksf "Blue" ~f "%s %d" "yolo" 42
will behave like
CCFormat.ksprintf
, but wrapping the content with the given style
Example:
the following with raise Failure
with a colored message
CCFormat.with_color_ksf "red" ~f:failwith "%a" CCFormat.Dump.(list int) [1;2;3];;
val output : t -> 'a printer -> 'a -> unit
val to_string : 'a printer -> 'a -> string
val of_chan : Pervasives.out_channel -> t
Format.formatter_of_out_channel
val with_out_chan : Pervasives.out_channel -> (t -> 'a) -> 'a
with_out_chan oc f
turns oc
into a formatter fmt
, and call f fmt
.
Behaves like f fmt
from then on, but whether the call to f
fails
or returns, fmt
is flushed before the call terminates.val stdout : t
val stderr : t
val tee : t -> t -> t
tee a b
makes a new formatter that writes in both a
and b
.val sprintf : ('a, t, unit, string) Pervasives.format4 -> 'a
CCFormat.fprintf
. Similar to Format.asprintf
.val sprintf_no_color : ('a, t, unit, string) Pervasives.format4 -> 'a
val sprintf_dyn_color : colors:bool -> ('a, t, unit, string) Pervasives.format4 -> 'a
CCFormat.sprintf
but enable/disable colors depending on colors
.
Example:
(* with colors *)
CCFormat.sprintf_dyn_color ~colors:true "@{<Red>%a@}"
CCFormat.Dump.(list int) [1;2;3] |> print_endline;;
(* without colors *)
CCFormat.sprintf_dyn_color ~colors:false "@{<Red>%a@}"
CCFormat.Dump.(list int) [1;2;3] |> print_endline;;
val fprintf : t -> ('a, t, unit) Pervasives.format -> 'a
Format.fprintf
val fprintf_dyn_color : colors:bool -> t -> ('a, t, unit) Pervasives.format -> 'a
val ksprintf : f:(string -> 'b) -> ('a, Format.formatter, unit, 'b) Pervasives.format4 -> 'a
ksprintf fmt ~f
formats using fmt
, in a way similar to CCFormat.sprintf
,
and then calls f
on the resulting string.val to_file : string -> ('a, t, unit, unit) Pervasives.format4 -> 'a
Print structures as OCaml values, so that they can be parsed back by OCaml (typically, in the toplevel, for debugging).
Example:
Format.printf "%a@." CCFormat.Dump.(list int) CCList.(1 -- 200);;
Format.printf "%a@." CCFormat.Dump.(array (list (pair int bool)))
[| [1, true; 2, false]; []; [42, false] |];;
module Dump:sig
..end