Module: GitHooker::TerminalColors

Extended by:
TerminalColors
Included in:
Action, Runner, Section, TerminalColors
Defined in:
lib/githooker/terminal_colors.rb

Constant Summary collapse

NORMAL =
"\033[0;0m"
MARK_SUCCESS =
''
MARK_FAILURE =
'X'
MARK_UNKNOWN =
'?'

Instance Method Summary collapse

Instance Method Details

#color(name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/githooker/terminal_colors.rb', line 12

def color(name)
  return "" unless $stdout.tty? && $stderr.tty?
  return NORMAL if !!name.to_s.match(/norm/)

  light = !!name.to_s.match(/(light|bright)/) ? "1" : "0"
  blink = !!name.to_s.match(/blink/)

  color_code = 30 + case name.to_s
    when /black/, /gray/ then 0
    when /red/ then 1
    when /green/ then 2
    when /yellow/ then 3
    when /blue/ then 4
    when /magenta/,/purple/ then 5
    when /cyan/ then 6
    when /white/ then 7
    else return NORMAL
  end

  return "\033[#{light};5;#{color_code}m" if blink
  return "\033[#{light};#{color_code}m"
end