include module type of sig ... end
val pp_open_box : formatter ‑> int ‑> unit
val pp_close_box : formatter ‑> unit ‑> unit
val pp_open_hbox : formatter ‑> unit ‑> unit
val pp_open_vbox : formatter ‑> int ‑> unit
val pp_open_hvbox : formatter ‑> int ‑> unit
val pp_open_hovbox : formatter ‑> int ‑> unit
val pp_print_string : formatter ‑> string ‑> unit
val pp_print_as : formatter ‑> int ‑> string ‑> unit
val pp_print_int : formatter ‑> int ‑> unit
val pp_print_float : formatter ‑> float ‑> unit
val pp_print_char : formatter ‑> char ‑> unit
val pp_print_bool : formatter ‑> bool ‑> unit
val pp_print_space : formatter ‑> unit ‑> unit
val pp_print_cut : formatter ‑> unit ‑> unit
val pp_print_break : formatter ‑> int ‑> int ‑> unit
val pp_force_newline : formatter ‑> unit ‑> unit
val pp_print_if_newline : formatter ‑> unit ‑> unit
val pp_print_flush : formatter ‑> unit ‑> unit
val pp_print_newline : formatter ‑> unit ‑> unit
val pp_set_margin : formatter ‑> int ‑> unit
val pp_get_margin : formatter ‑> unit ‑> int
val pp_set_max_indent : formatter ‑> int ‑> unit
val pp_get_max_indent : formatter ‑> unit ‑> int
val pp_set_max_boxes : formatter ‑> int ‑> unit
val pp_get_max_boxes : formatter ‑> unit ‑> int
val pp_over_max_boxes : formatter ‑> unit ‑> bool
val pp_open_tbox : formatter ‑> unit ‑> unit
val pp_close_tbox : formatter ‑> unit ‑> unit
val pp_set_tab : formatter ‑> unit ‑> unit
val pp_print_tab : formatter ‑> unit ‑> unit
val pp_print_tbreak : formatter ‑> int ‑> int ‑> unit
val pp_set_ellipsis_text : formatter ‑> string ‑> unit
val pp_get_ellipsis_text : formatter ‑> unit ‑> string
val pp_open_tag : formatter ‑> string ‑> unit
val open_tag : tag ‑> unit
val pp_close_tag : formatter ‑> unit ‑> unit
val pp_set_tags : formatter ‑> bool ‑> unit
val pp_set_print_tags : formatter ‑> bool ‑> unit
val pp_set_mark_tags : formatter ‑> bool ‑> unit
val pp_get_print_tags : formatter ‑> unit ‑> bool
val pp_get_mark_tags : formatter ‑> unit ‑> bool
val pp_set_formatter_out_channel : formatter ‑> Pervasives.out_channel ‑> unit
val pp_set_formatter_output_functions : formatter ‑> (string ‑> int ‑> int ‑> unit) ‑> (unit ‑> unit) ‑> unit
val pp_get_formatter_output_functions : formatter ‑> unit ‑> (string ‑> int ‑> int ‑> unit) * (unit ‑> unit)
val pp_set_formatter_out_functions : formatter ‑> formatter_out_functions ‑> unit
val set_formatter_out_functions : formatter_out_functions ‑> unit
val pp_get_formatter_out_functions : formatter ‑> unit ‑> formatter_out_functions
val get_formatter_out_functions : unit ‑> formatter_out_functions
val pp_set_formatter_tag_functions : formatter ‑> formatter_tag_functions ‑> unit
val set_formatter_tag_functions : formatter_tag_functions ‑> unit
val pp_get_formatter_tag_functions : formatter ‑> unit ‑> formatter_tag_functions
val get_formatter_tag_functions : unit ‑> formatter_tag_functions
val formatter_of_out_channel : Pervasives.out_channel ‑> formatter
val std_formatter : formatter
val err_formatter : formatter
val formatter_of_buffer : Buffer.t ‑> formatter
val str_formatter : formatter
val make_formatter : (string ‑> int ‑> int ‑> unit) ‑> (unit ‑> unit) ‑> formatter
val formatter_of_out_functions : formatter_out_functions ‑> formatter
val make_symbolic_output_buffer : unit ‑> symbolic_output_buffer
val clear_symbolic_output_buffer : symbolic_output_buffer ‑> unit
val get_symbolic_output_buffer : symbolic_output_buffer ‑> symbolic_output_item list
val flush_symbolic_output_buffer : symbolic_output_buffer ‑> symbolic_output_item list
val add_symbolic_output_item : symbolic_output_buffer ‑> symbolic_output_item ‑> unit
val formatter_of_symbolic_output_buffer : symbolic_output_buffer ‑> formatter
val pp_print_text : formatter ‑> string ‑> unit
val printf : ('a, formatter, unit) Pervasives.format ‑> 'a
val eprintf : ('a, formatter, unit) Pervasives.format ‑> 'a
val asprintf : ('a, formatter, unit, string) Pervasives.format4 ‑> 'a
val kasprintf : (string ‑> 'a) ‑> ('b, formatter, unit, 'a) Pervasives.format4 ‑> 'b
val bprintf : Buffer.t ‑> ('a, formatter, unit) Pervasives.format ‑> 'a
val kprintf : (string ‑> 'a) ‑> ('b, unit, string, 'a) Pervasives.format4 ‑> 'b
val set_all_formatter_output_functions : out:(string ‑> int ‑> int ‑> unit) ‑> flush:(unit ‑> unit) ‑> newline:(unit ‑> unit) ‑> spaces:(int ‑> unit) ‑> unit
val get_all_formatter_output_functions : unit ‑> (string ‑> int ‑> int ‑> unit) * (unit ‑> unit) * (unit ‑> unit) * (int ‑> unit)
val pp_set_all_formatter_output_functions : formatter ‑> out:(string ‑> int ‑> int ‑> unit) ‑> flush:(unit ‑> unit) ‑> newline:(unit ‑> unit) ‑> spaces:(int ‑> unit) ‑> unit
val pp_get_all_formatter_output_functions : formatter ‑> unit ‑> (string ‑> int ‑> int ‑> unit) * (unit ‑> unit) * (unit ‑> unit) * (int ‑> unit)
val int : int printer
val string : string printer
val bool : bool printer
val float3 : float printer
val float : float printer
val substring : (string * int * int) printer
Print the substring (s,i,len)
, where i
is the offset
in s
and len
the number of bytes in the substring.
(s,i,len)
does not
describe a proper substring.val text : string printer
Print string, but replacing spaces with breaks and newlines
with newline.
See pp_print_text
on recent versions of OCaml.
opt pp
prints options as follows:
Some x
will become "some foo" if pp x ---> "foo"
.None
will become "none".In the tuple printers, the sep
argument is only available.
within a b p
wraps p
inside the strings a
and b
. Convenient,
for instances, for brackets, parenthesis, quotes, etc.
Wrap the printer in a vertical box.
Wrap the printer in a horizontal/vertical box.
Wrap the printer in a horizontal or vertical box.
val return : ('a, _, _, '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 string.
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: unstable
val set_color_tag_handling : t ‑> unit
Add functions to support color tags to the given formatter.
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 sprintf formatters;
it disables the color handling if b = false
.
with_color "Blue" pp
behaves like the printer pp
, but with the given
style.
status: unstable
with_colorf "Blue" out "%s %d" "yolo" 42
will behave like Format.fprintf,
but wrapping the content with the given style.
status: unstable
val with_color_sf : string ‑> ('a, t, unit, string) Pervasives.format4 ‑> 'a
with_color_sf "Blue" out "%s %d" "yolo" 42
will behave like
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: unstable
val 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
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 to_string : 'a printer ‑> 'a ‑> string
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 sprintf : ('a, t, unit, string) Pervasives.format4 ‑> 'a
Print into a string any format string that would usually be compatible with fprintf. Like Format.asprintf.
val sprintf_no_color : ('a, t, unit, string) Pervasives.format4 ‑> 'a
Like sprintf but never prints colors.
val sprintf_dyn_color : colors:bool ‑> ('a, t, unit, string) Pervasives.format4 ‑> 'a
Like 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;;
Like fprintf but enable/disable colors depending on colors
.
val ksprintf : ?margin:int ‑> f:(string ‑> 'b) ‑> ('a, Format.formatter, unit, 'b) Pervasives.format4 ‑> 'a
ksprintf fmt ~f
formats using fmt
, in a way similar to sprintf,
and then calls f
on the resulting string.
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