Page
Library
Module
Module type
Parameter
Class
Class type
Source
Ansi.ColorRepresents a ANSI color. It can be either 8-bit, which provides a portable palette of 256 colors, or 24-bit (RGB), which gives more granularity.
The 256-color palette can be found on the Wikipedia article on ANSI escape sequences: https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
NOTE: Each constructor would normally expect integers between 0 and 255 - for convenience, they operate with the built-in int type which is technically too permissive, but allows direct use of numeric literals. To prevent generating invalid escape sequences, the integers get therefore normalized by taking their absolute value modulo 256.
val to_attributes : [ `Foreground | `Background ] -> t -> Attributes.tto_attributes ground color produces the attribute record of the color.
Since the code depends on whether the color is applied to the foreground or the background, this latter piece of information must also be provided via ground.
color1 = color2 determines whether two colors are equal.
Note: `Basic colors are never equal to `Rgb ones even if your terminal renders them identically.
These constants are provided for convenience. They correspond to the 4-bit ANSI colors.
val black : tval red : tval green : tval yellow : tval blue : tval magenta : tval cyan : tval white : tval bright_black : tval bright_red : tval bright_green : tval bright_yellow : tval bright_blue : tval bright_magenta : tval bright_cyan : tval bright_white : tThese functions are equivalent to the type's constructors but check the integer values instead of normalizing them.
basic index constructs a 8-bit color. index must be between 0 and 255 (both included) ; otherwise, it returns None.
rgb (r, g, b) constructs an RGB color. All channels must be between 0 and 255 (both included) ; otherwise, it returns None.
val serialize : t -> stringserialize color produces a serialized representation of the color.
Tip: the serialized color can be retreived back using parse.
Note: colors are normalized before serialization.
These functions parse strings to get a color from them.
of_hex_repr string attempts to parse the string as the representation of an hexadecimal number.
It allows:
#f864a0, optional)#ddd)val parse : string -> t optionparse string attempts to find a serialized color in the string.
It supports rgb(r, g, b) and basic(n), ignoring spaces and case. Numbers greater than 255 are allowed, but not less than 0.
luminance color returns the luminance of the color as a floating-point number between 0 and 1.
Important: This is NOT a function to estimate perceived lightness. For that, see perceived_lightness.
Note: the color is normalized before calculation.
Note: this function is only available for RGB colors.
perceived_lightness color returns the perceived lightness of the color as an integer between 0 and 100.
Note: the color is normalized before calculation.
Note: this function is only available for RGB colors.
best_for_contrast color determines whether a light or dark opposite color is best.
For example, if color is a background color, this function will tell whether the text written on top of it should be light or dark for the best readability.
Note: the calculation is based on perceived lightness.
Note: the color is normalized before calculation.
Note: this function is only available for RGB colors.
module Basic : sig ... endFunctions to deal with basic colors.
module Rgb : sig ... endFunctions to deal with RGB colors.