Module: Wirb::Colorizer::Wirb0_HighLine

Defined in:
lib/wirb/colorizer/wirb0_highline.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.color(*colors) ⇒ Object



16
17
18
# File 'lib/wirb/colorizer/wirb0_highline.rb', line 16

def self.color(*colors)
  ::HighLine.color_code(*color_name(*colors))
end

.color_name(*colors) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/wirb/colorizer/wirb0_highline.rb', line 25

def self.color_name(*colors)
  colors = colors.flatten.compact
  if colors.first == :highline # In this case, colors already use HighLine's names
    colors[1..-1]
  else
    translated_colors = colors.map do |color|
      color = color.to_s
      case color
      when "nothing"
        color = "clear"
      when /light_gray/
         color = color.sub("light_gray", "white")
      when /dark_gray/
         color = color.sub("dark_gray", "light_black")  # Changed to [:bold, :black] below
      when /yellow/
        color = color.sub("yellow", "light_yellow")     # Changed to [:bold, :yellow] below
      when /white/
         color = color.sub("white", "light_white")      # Changed to [:bold, :white] below
      when /brown/              
        color = color.sub("brown", "yellow")
      when /purple/             
        color = color.sub("purple", "magenta")
      end
      color_set = [color.to_sym]
      if color_set.first.to_s =~ /^light_(.*)/
        color_set[0] = $1.to_sym
        color_set << :bold
      end
      case color_set.first.to_s
      when /(.*)_underline$/
        color_set[0] = [$1.to_sym]
        color_set << :underline
      when /(.*)_background$/
        color_set[0] = [('on_'+$1).to_sym]
      end
      color_set
    end
    translated_colors.flatten
  end
end

.run(s, *colors) ⇒ Object



20
21
22
# File 'lib/wirb/colorizer/wirb0_highline.rb', line 20

def self.run(s, *colors)
  ::HighLine.color(s, *color_name(*colors))
end

Instance Method Details

#color(*args) ⇒ Object



70
71
72
# File 'lib/wirb/colorizer/wirb0_highline.rb', line 70

def color(*args)
  self.class.color(*args)
end

#color_code(*args) ⇒ Object



66
67
68
# File 'lib/wirb/colorizer/wirb0_highline.rb', line 66

def color_code(*args)
  self.class.color_code(*args)
end