class
Term::Color
- Term::Color
- Reference
- Object
Included Modules
- Comparable(Term::Color)
- Term::Color::Colors
Defined in:
color/color.crcolor/colors.cr
color/env.cr
color/version.cr
Constant Summary
-
ANSI_COLOR_REGEXP =
/\x1b+(\[|\[\[)[0-9;:?]+m/m -
Color strips only SGR color/style sequences; use
Term::Cursor.strip_ansiwhen non-color terminal escape sequences should be removed too. -
VERSION =
"1.0.0"
Constructors
-
.new(red, green, blue, alpha = 255)
Creates a new
Term::Colorinstance from#red,#green,#blueand#alphavalues. -
.new(hex : String)
Creates a new
Term::Colorinstance from a hex string.
Class Method Summary
-
.color(color)
Gets one of the many color values defined in
COLORSas aTerm::Colorinstance. -
.command?(cmd : String, args : Array(String) = [] of String)
Check if a command exists and can run with given args
-
.enabled=(value : Bool | Nil)
Set to nil to reset to terminal capability auto-detection.
- .enabled? : Bool
-
.from_hsb(h, s, b)
Create a new
Term::Colorinstance from hue, saturation, and brightness. -
.from_hsl(h, s, l)
Create a new
Term::Colorinstance from hue, saturation, and lightness. -
.from_hsv(h, s, v)
Create a new
Term::Colorinstance 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. -
.tty?
True if STDOUT is a TTY
-
.windows?
True if running on Windows
Instance Method Summary
- #*(other : Term::Color)
- #+(other : Term::Color)
- #-(other : Term::Color)
- #/(other : Term::Color)
-
#<=>(other)
Implements the comparison operator for
Term::Color. -
#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
Term::Colorinstance as ahexstring. -
#inverse
Returns a new
Term::Colorthat'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
Term::Colorinstance as a cssrgb(a)string. -
#to_a
Convert the
Term::Colorto an array. -
#to_h
Convert the
Term::Colorto 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
Term::Colorto a tuple.
Constructor Detail
Creates a new Term::Color instance from #red, #green, #blue
and #alpha values.
Class Method Detail
Gets one of the many color values defined in COLORS
as a Term::Color instance.
Check if a command exists and can run with given args
Create a new Term::Color instance from hue, saturation, and brightness.
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 Term::Color 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 Term::Color instance as a hex string.