package ocolor

  1. Overview
  2. Docs

Printf-friendly functions

These functions are useful when trying to print with styles with Printf. However, they are a very bad choice. They perform a context-free formatting. For instance, there is no way to end the current style and restore the previous, like stack-base functions of Ocolor_format do. They just print the desired style and keep no track of the current state.

Thus, it's better to use Ocolor_format as much as possible. Moreover, Format provide a nice way of composing printers with %a and Format.asprintf. Even if you don't like boxes, Format.asprintf and semantic tags are cool.

So, here are the Printf-friendly functions. Use with care, and preferably, not at all.

fprintf

%a

val apply_style : Stdlib.out_channel -> Ocolor_types.style -> unit
val apply_styles : Stdlib.out_channel -> Ocolor_types.style list -> unit
val fg_color4 : Stdlib.out_channel -> Ocolor_types.color4 -> unit
val fg_color8 : Stdlib.out_channel -> Ocolor_types.color8 -> unit
val fg_color24 : Stdlib.out_channel -> Ocolor_types.color24 -> unit
val bg_color4 : Stdlib.out_channel -> Ocolor_types.color4 -> unit
val bg_color8 : Stdlib.out_channel -> Ocolor_types.color8 -> unit
val bg_color24 : Stdlib.out_channel -> Ocolor_types.color24 -> unit

%t

val default_fg : Stdlib.out_channel -> unit
val fg_rgb : int -> int -> int -> Stdlib.out_channel -> unit
val default_bg : Stdlib.out_channel -> unit
val bg_rgb : int -> int -> int -> Stdlib.out_channel -> unit
val reset : Stdlib.out_channel -> unit

sprintf

%a

val s_apply_style : unit -> Ocolor_types.style -> string
val s_apply_styles : unit -> Ocolor_types.style list -> string

Printf-like

Just like printf but perform automatic reset after printing if Ocolor_config.auto_reset is set

val fprintf : Stdlib.out_channel -> ('a, Stdlib.out_channel, unit) Stdlib.format -> 'a
val kfprintf : (Stdlib.out_channel -> unit) -> Stdlib.out_channel -> ('a, Stdlib.out_channel, unit) Stdlib.format -> 'a
val sprintf : ('a, unit, string, string) Stdlib.format4 -> 'a
val printf : ('a, Stdlib.out_channel, unit) Stdlib.format -> 'a
val kprintf : (Stdlib.out_channel -> unit) -> ('a, Stdlib.out_channel, unit) Stdlib.format -> 'a

Handy printers

val pp_bool_generic : ?false_style:Ocolor_types.style list -> ?true_style:Ocolor_types.style list -> Stdlib.out_channel -> bool -> unit
val pp_bool : Stdlib.out_channel -> bool -> unit
val pp_list_generic : ?left:string -> ?sep:string -> ?right:string -> ?delim_style:Ocolor_types.style list -> ?sep_style:Ocolor_types.style list -> ?elem_style:Ocolor_types.style list -> (Stdlib.out_channel -> 'a -> unit) -> Stdlib.out_channel -> 'a list -> unit
val pp_list : (Stdlib.out_channel -> 'a -> unit) -> Stdlib.out_channel -> 'a list -> unit
val pp_option_generic : ?none:string -> ?none_style:Ocolor_types.style list -> ?some_style:Ocolor_types.style list -> (Stdlib.out_channel -> 'a -> unit) -> Stdlib.out_channel -> 'a option -> unit
val pp_option : (Stdlib.out_channel -> 'a -> unit) -> Stdlib.out_channel -> 'a option -> unit
val pp_pair_generic : ?left:string -> ?sep:string -> ?right:string -> ?delim_style:Ocolor_types.style list -> ?sep_style:Ocolor_types.style list -> ?elem_style:Ocolor_types.style list -> (Stdlib.out_channel -> 'a -> unit) -> (Stdlib.out_channel -> 'b -> unit) -> Stdlib.out_channel -> ('a * 'b) -> unit
val pp_pair : (Stdlib.out_channel -> 'a -> unit) -> (Stdlib.out_channel -> 'b -> unit) -> Stdlib.out_channel -> ('a * 'b) -> unit
val pp_3_tuple_generic : ?left:string -> ?sep:string -> ?right:string -> ?delim_style:Ocolor_types.style list -> ?sep_style:Ocolor_types.style list -> ?elem_style:Ocolor_types.style list -> (Stdlib.out_channel -> 'a -> unit) -> (Stdlib.out_channel -> 'b -> unit) -> (Stdlib.out_channel -> 'c -> unit) -> Stdlib.out_channel -> ('a * 'b * 'c) -> unit
val pp_3_tuple : (Stdlib.out_channel -> 'a -> unit) -> (Stdlib.out_channel -> 'b -> unit) -> (Stdlib.out_channel -> 'c -> unit) -> Stdlib.out_channel -> ('a * 'b * 'c) -> unit
val pp_4_tuple_generic : ?left:string -> ?sep:string -> ?right:string -> ?delim_style:Ocolor_types.style list -> ?sep_style:Ocolor_types.style list -> ?elem_style:Ocolor_types.style list -> (Stdlib.out_channel -> 'a -> unit) -> (Stdlib.out_channel -> 'b -> unit) -> (Stdlib.out_channel -> 'c -> unit) -> (Stdlib.out_channel -> 'd -> unit) -> Stdlib.out_channel -> ('a * 'b * 'c * 'd) -> unit
val pp_4_tuple : (Stdlib.out_channel -> 'a -> unit) -> (Stdlib.out_channel -> 'b -> unit) -> (Stdlib.out_channel -> 'c -> unit) -> (Stdlib.out_channel -> 'd -> unit) -> Stdlib.out_channel -> ('a * 'b * 'c * 'd) -> unit
val pp_5_tuple_generic : ?left:string -> ?sep:string -> ?right:string -> ?delim_style:Ocolor_types.style list -> ?sep_style:Ocolor_types.style list -> ?elem_style:Ocolor_types.style list -> (Stdlib.out_channel -> 'a -> unit) -> (Stdlib.out_channel -> 'b -> unit) -> (Stdlib.out_channel -> 'c -> unit) -> (Stdlib.out_channel -> 'd -> unit) -> (Stdlib.out_channel -> 'e -> unit) -> Stdlib.out_channel -> ('a * 'b * 'c * 'd * 'e) -> unit
val pp_5_tuple : (Stdlib.out_channel -> 'a -> unit) -> (Stdlib.out_channel -> 'b -> unit) -> (Stdlib.out_channel -> 'c -> unit) -> (Stdlib.out_channel -> 'd -> unit) -> (Stdlib.out_channel -> 'e -> unit) -> Stdlib.out_channel -> ('a * 'b * 'c * 'd * 'e) -> unit
OCaml

Innovation. Community. Security.