class Cor
- Cor
- Reference
- Object
Overview
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.
Included Modules
- Comparable(Cor)
- Cor::Colors
Defined in:
cor.crcor/colors.cr
cor/cor.cr
cor/version.cr
Constant Summary
-
ANSI_COLOR_REGEXP =
/\x1b+(\[|\[\[)[0-9;:?]+m/m -
VERSION =
"0.1.0"
Constructors
- .new(red, green, blue, alpha = 255)
-
.new(hex : String)
Creates a new
Corinstance from a hex string.
Class Method Summary
- .color(color)
-
.from_hsb(h, s, b)
Create a new
Corinstance from hue, saturation, and brightness. -
.from_hsl(h, s, l)
Create a new
Corinstance from hue, saturation, and lightness. -
.from_hsv(h, s, v)
Create a new
Corinstance from hue, saturation, and value. -
.strip(string)
Strip ANSI color codes from a string.
-
.truecolor_string(string : String, fore = nil, back = nil, bold = false, faint = false, italic = false, underline = false, blink = false, strike = false, overline = false)
Converts
stringto an ANSI escape sequence for use with truecolor enabled terminals.
Instance Method Summary
- #*(other : Cor)
- #+(other : Cor)
- #-(other : Cor)
- #/(other : Cor)
-
#<=>(other)
Implements the comparison operator for
Cor. -
#alpha : Int32
alpha (opacity) value for this color
-
#alpha=(value)
Set the alpha value for this color.
-
#blue : Int32
blue value for this color
-
#blue=(value)
Set the blue value for this color
-
#green : Int32
green value for this color
-
#green=(value)
Set the green value for this color
-
#hex_string(prefix = false, alpha = false, upcase = false)
Outputs this
Corinstance as ahexstring. -
#inverse
Returns a new
Corthat's the inverse of self. -
#pretty_print(pp)
Pretty print (it's a rainbow!)
-
#red : Int32
red value for this color
-
#red=(value)
Set the red value for this color
-
#rgb_string(alpha = false)
Outputs this
Corinstance as a cssrgb(a)string. -
#to_a
Convert the
Corto an array. -
#to_h
Convert the
Corto a hash. -
#to_hsb
The HSb (hue / saturation / brightness) of the color
-
#to_hsl
The HSV (hue / saturation / lightness) of the color
-
#to_hsv
The HSV (hue / saturation / value) of the color
-
#to_s
Convert to a string
-
#to_tuple
Convert the
Corto a tuple.
Constructor Detail
Class Method Detail
Strip ANSI color codes from a string.
Only ANSI color codes are removed, not movement codes or other escapes sequences are stripped.
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.
Instance Method Detail
Set the alpha value for this color. Can be either a float between 0 and 1, or a integer value between 0 and 255.
Outputs this Cor instance as a hex string.