package ansifmt

  1. Overview
  2. Docs

Module Ansifmt.ColorSource

Color encodes ANSI colors.

It comes in three flavors:

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

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

Sourceval foreground : Ground.t
Sourceval background : Ground.t
Sourcemodule Minimal : sig ... end

Minimal encodes the 8 default ANSI colors.

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

Default black color.

Sourceval red : t

Default red color.

Sourceval green : t

Default green color.

Sourceval yellow : t

Default yellow color.

Sourceval blue : t

Default blue color.

Sourceval magenta : t

Default magenta color.

Sourceval cyan : t

Default cyan color.

Sourceval white : t

Default white color.

Sourceval bright_black : t

Default bright black (gray) color.

Sourceval bright_red : t

Default bright red color.

Sourceval bright_green : t

Default bright green color.

Sourceval bright_yellow : t

Default bright yellow color.

Sourceval bright_blue : t

Default bright blue color.

Sourceval bright_magenta : t

Default bright magenta color.

Sourceval bright_cyan : t

Default bright cyan color.

Sourceval bright_white : t

Default bright white color.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourcemodule Channel : sig ... end
Sourceval make_rgb : int -> int -> int -> (t, Channel.t) 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.