package ansifmt

  1. Overview
  2. Docs
type t = {
  1. foreground : Color.t option;
  2. background : Color.t option;
  3. bold : bool;
  4. dim : bool;
  5. italic : bool;
  6. underlined : bool;
}
val none : t

none is the empty styling.

val create : ?foreground:[< Color.t ] -> ?background:[< Color.t ] -> ?bold:bool -> ?dim:bool -> ?italic:bool -> ?underlined:bool -> unit -> t

create ?foreground ?background ?bold ?dim ?italic ?underlined () creates a new style object given the provided configuration.

val fg : [< Color.t ] -> t

fg color is a convenient constructor for creating composable styles. Creates a style with the specified foreground color only. See & for usage examples.

val bg : [< Color.t ] -> t

fg color is a convenient constructor for creating composable styles. Creates a style with the specified background color only. See & for usage examples.

val bold : t

bold is a convenient constructor for creating composable styles. Creates a bold style only. See & for usage examples.

val dim : t

dim is a convenient constructor for creating composable styles. Creates a dim style only. See & for usage examples.

val italic : t

italic is a convenient constructor for creating composable styles. Creates an italic style only. See & for usage examples.

val underlined : t

underlined is a convenient constructor for creating composable styles. Creates an underline style only. See & for usage examples.

val (&) : t -> t -> t

left & right combines two styles with the following rules:

  • For colors, right is taken if it's present, otherwise left
  • For boolean fields, the or combination of both is applied

Usage example:

let my_style = Styling.(default_style & fg yellow & bg black & bold) in
val to_ansi : t -> string

to_ansi styling renders the styling to an ANSI escape sequence as a string.

val wrap : contents:string -> t -> string

wrap ~contents styling wraps contents in an ANSI escape sequence using styling.

OCaml

Innovation. Community. Security.