Cor (which means color in Portuguese) is a library for more easily
working with colors in Crystal. You can think of it as a more
powerful version of Colorize. Cor allows you to very
easily convert RGB(A) values to hex and back again for
use in CSS and HTML. It also provides a set of
chainable methods for creting colorful strings
for the terminal using truecolor.
For full usage instructions see the README.
Constants
ANSI_COLOR_REGEXP = /\x1b+(\[|\[\[)[0-9;:?]+m/m
Constructors
new(red, green, blue, alpha = 255)
Creates a new Cor instance from red, green, blue
and alpha values.
SourceCreates a new Cor instance from a hex string.
SourceClass methods
color(color)
Gets one of the many color values defined in COLORS
as a Cor instance.
Sourcefrom_hsb(h, s, b)
Create a new Cor instance from hue, saturation, and brightness.
Sourcefrom_hsl(h, s, l)
Create a new Cor instance from hue, saturation, and lightness.
Sourcefrom_hsv(h, s, v)
Create a new Cor instance from hue, saturation, and value.
Sourcestrip(string)
Strip ANSI color codes from a string.
Only ANSI color codes are removed, not movement codes or
other escapes sequences are stripped.
Sourcetruecolor_string(string :
String, fore = nil, back = nil, bold = false, faint = false, italic = false, underline = false, blink = false, strike = false, overline = false)
Converts string to an ANSI escape sequence for use with
truecolor enabled terminals. fore and
back can be either a Cor instance or
a symbol representing a COLORS value.
SourceInstance methods
<=>(other)
Implements the comparison operator for Cor.
Sourcealpha
alpha (opacity) value for this color
Sourcealpha=(value)
Set the alpha value for this color. Can be either
a float between 0 and 1, or a integer value
between 0 and 255.
Sourceblue
blue value for this color
Sourceblue=(value)
Set the blue value for this color
Sourcegreen
green value for this color
Sourcegreen=(value)
Set the green value for this color
Sourcehex_string(prefix = false, alpha = false, upcase = false)
Outputs this Cor instance as a hex string.
Sourceinverse
Returns a new Cor that's the inverse of self.
Sourcepretty_print(pp)
Pretty print (it's a rainbow!)
Sourcered=(value)
Set the red value for this color
Sourcergb_string(alpha = false)
Outputs this Cor instance as a css rgb(a) string.
Sourceto_a
Convert the Cor to an array.
Sourceto_h
Convert the Cor to a hash.
Sourceto_hsb
The HSb (hue / saturation / brightness) of the color
Sourceto_hsl
The HSV (hue / saturation / lightness) of the color
Sourceto_hsv
The HSV (hue / saturation / value) of the color
Sourceto_tuple
Convert the Cor to a tuple.
Source