package ansifmt
Module Ansifmt.ColorSource
Color encodes ANSI colors.
It comes in three flavors:
- 4-bit (
Minimal) - 8-bit (
Advanced) - 24-bit (
Rgb)
Ground encodes the information on whether a certain color is on the foreground or the background.
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.
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.
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.
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.
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.
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.
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.
make_rgb_hex str parses an RGB color from a string str like 7057fc or #fbca04
to_ansi color produces an SGR escape portion that can be embedded in a string based on the color.
This function returns luminance of an RGB color in range between 0 and 255.
See best_for_contrast for a usage example.
best_for_contrast ~threshold rgb takes a color rgb, threshold between 0 and 255 (both inclusive) representing luminescence tolerance, and returns the suggested color theme for the opposite color to achieve the best contrast.
For example, if rgb is a background colour, and best_for_contrast return `Light, you should select a light foreground colour for the best readability.
- NOTE: Default
thresholdvalue is 128. - NOTE: Higher
thresholdwill suggest`Lightmore often and on brighter colours. Lowerthresholdwill suggest`Lightfor darker colours. The opposite is true for`Dark.