Class: CLI::UI::Color

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
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)
MAP =
{
  red: RED,
  green: GREEN,
  yellow: YELLOW,
  blue: BLUE,
  magenta: MAGENTA,
  cyan: CYAN,
  reset: RESET,
  bold: BOLD,
  gray: GRAY,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from T::Sig

sig

Constructor Details

#initialize(sgr, name) ⇒ Color

Returns a new instance of Color.



26
27
28
29
30
# File 'lib/cli/ui/color.rb', line 26

def initialize(sgr, name)
  @sgr  = sgr
  @code = CLI::UI::ANSI.sgr(sgr)
  @name = name
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



11
12
13
# File 'lib/cli/ui/color.rb', line 11

def code
  @code
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/cli/ui/color.rb', line 14

def name
  @name
end

#sgrObject (readonly)

Returns the value of attribute sgr.



11
12
13
# File 'lib/cli/ui/color.rb', line 11

def sgr
  @sgr
end

Class Method Details

.availableObject



97
98
99
# File 'lib/cli/ui/color.rb', line 97

def available
  MAP.keys
end

.lookup(name) ⇒ Object



88
89
90
91
92
# File 'lib/cli/ui/color.rb', line 88

def lookup(name)
  MAP.fetch(name.to_sym)
rescue KeyError
  raise InvalidColorName, name.to_sym
end