package ansifmt

  1. Overview
  2. Docs

Color encodes ANSI colors.

It comes in three flavors:

  • 4-bit (Minimal)
  • 8-bit (Advanced)
  • 24-bit (Rgb)
module Ground : sig ... end

Ground encodes the information on whether a certain color is on the foreground or the background.

val foreground : Ground.t
val background : Ground.t
module Minimal : sig ... end

Minimal encodes the 8 default ANSI colors.

type t =
  1. | Minimal of {
    1. color : Minimal.t;
    2. bright : bool;
    }
  2. | Advanced of int
  3. | Rgb of int * int * int
val black : t

Default black color.

val red : t

Default red color.

val green : t

Default green color.

val yellow : t

Default yellow color.

val blue : t

Default blue color.

val magenta : t

Default magenta color.

val cyan : t

Default cyan color.

val white : t

Default white color.

val bright_black : t

Default bright black (gray) color.

val bright_red : t

Default bright red color.

val bright_green : t

Default bright green color.

val bright_yellow : t

Default bright yellow color.

val bright_blue : t

Default bright blue color.

val bright_magenta : t

Default bright magenta color.

val bright_cyan : t

Default bright cyan color.

val bright_white : t

Default bright white color.

val make_minimal : ?bright:bool -> int -> t option

make_minimal ?bright value creates a minimal color. If value is not a valid color code, it returns None.

A valid color code is an integer i where 0 <= i <= 7.

val make_minimal_exn : ?bright:bool -> int -> t

make_minimal_exn ?bright value creates a minimal color. If value is not a valid color code, it raises a Failure exception.

A valid color code is an integer i where 0 <= i <= 7.

val make_advanced : int -> t option

make_advanced value creates an advanced color. If value is not a valid color code, it returns None.

A valid color code is an integer i where 0 <= i < 256.

val make_advanced_exn : int -> t

make_advanced_exn value creates an advanced color. If value is not a valid color code, it raises a Failure exception.

A valid color code is an integer i where 0 <= i < 256.

module Channel : sig ... end
val make_rgb : int -> int -> int -> (t, Channel.t) Stdlib.result

make_rgb red green blue creates an RGB color. If any of red, green or blue is not a valid channel value, it returns an Error which indicates which channel had an invalid value.

A valid channel value is an integer i where 0 <= i < 256.

For the version that returns an option instead, see make_rgb_opt.

val make_rgb_opt : int -> int -> int -> t option

make_rgb_opt red green blue creates an RGB color. If any of red, green or blue is not a valid channel value, it returns None.

A valid channel value is an integer i where 0 <= i < 256.

For the version that returns a result with the invalid channel data, see make_rgb.

val make_rgb_exn : int -> int -> int -> t

make_rgb_exn red green blue creates an RGB color. If any of red, green or blue is not a valid channel value, it raises a Failure exception.

A valid channel value is an integer i where 0 <= i < 256.

val to_ansi : ground:Ground.t -> t -> string

to_ansi color produces an SGR escape portion that can be embedded in a string based on the color.

OCaml

Innovation. Community. Security.