Class: CLI::UI::Color
- Inherits:
-
Object
- Object
- CLI::UI::Color
- Defined in:
- lib/cli/ui/color.rb
Defined Under Namespace
Classes: InvalidColorName
Constant Summary collapse
- RED =
new('31', :red)
- GREEN =
new('32', :green)
- YELLOW =
new('33', :yellow)
- BLUE =
default blue is low-contrast against black in some default terminal color scheme
new('94', :blue)
- MAGENTA =
new('35', :magenta)
- CYAN =
new('36', :cyan)
- RESET =
new('0', :reset)
- BOLD =
new('1', :bold)
- WHITE =
new('97', :white)
- GRAY =
240 is very dark gray; 255 is very light gray. 244 is somewhat dark.
new('38;5;244', :gray)
- ORANGE =
Using color 214 from the 256-color palette for a more distinct orange
new('38;5;214', :orange)
- MAP =
{ red: RED, green: GREEN, yellow: YELLOW, blue: BLUE, magenta: MAGENTA, cyan: CYAN, reset: RESET, bold: BOLD, gray: GRAY, orange: ORANGE, }.freeze
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
: String.
-
#name ⇒ Object
readonly
: Symbol.
-
#sgr ⇒ Object
readonly
: String.
Class Method Summary collapse
-
.available ⇒ Object
All available colors by name.
-
.lookup(name) ⇒ Object
Looks up a color code by name.
Instance Method Summary collapse
-
#initialize(sgr, name) ⇒ Color
constructor
Creates a new color mapping Signatures can be found here: en.wikipedia.org/wiki/ANSI_escape_code#Colors.
Constructor Details
#initialize(sgr, name) ⇒ Color
Creates a new color mapping Signatures can be found here: en.wikipedia.org/wiki/ANSI_escape_code#Colors
Attributes
-
sgr- The color signature -
name- The name of the color
: (String sgr, Symbol name) -> void
25 26 27 28 29 |
# File 'lib/cli/ui/color.rb', line 25 def initialize(sgr, name) @sgr = sgr @code = CLI::UI::ANSI.sgr(sgr) @name = name end |
Instance Attribute Details
#code ⇒ Object (readonly)
: String
10 11 12 |
# File 'lib/cli/ui/color.rb', line 10 def code @code end |
#name ⇒ Object (readonly)
: Symbol
13 14 15 |
# File 'lib/cli/ui/color.rb', line 13 def name @name end |
#sgr ⇒ Object (readonly)
: String
10 11 12 |
# File 'lib/cli/ui/color.rb', line 10 def sgr @sgr end |
Class Method Details
.available ⇒ Object
All available colors by name
: -> Array
95 96 97 |
# File 'lib/cli/ui/color.rb', line 95 def available MAP.keys end |
.lookup(name) ⇒ Object
Looks up a color code by name
Raises
Raises a InvalidColorName if the color is not available You likely need to add it to the MAP or you made a typo
Returns
Returns a color code
: ((Symbol | String) name) -> Color
86 87 88 89 90 |
# File 'lib/cli/ui/color.rb', line 86 def lookup(name) MAP.fetch(name.to_sym) rescue KeyError raise InvalidColorName, name.to_sym end |