Module: Sickill::Rainbow

Defined in:
lib/rainbow.rb

Constant Summary collapse

TERM_COLORS =
{ 
  :black => 0,
  :red => 1,
  :green => 2,
  :yellow => 3,
  :blue => 4,
  :magenta => 5,
  :cyan => 6,
  :white => 7,
  :default => 9,
}
TERM_EFFECTS =
{
  :reset => 0,
  :bright => 1,
  :italic => 3,
  :underline => 4,
  :blink => 5,
  :inverse => 7,
  :hide => 8,
}

Instance Method Summary collapse

Instance Method Details

#background(color) ⇒ Object

Sets background color of this text.



37
38
39
40
41
# File 'lib/rainbow.rb', line 37

def background(color)
  color = color.to_sym
  validate_color(color)
  wrap_with_code(TERM_COLORS[color] + 40)
end

Turns on blinking attribute for this text (not well supported by terminal emulators).



66
67
68
# File 'lib/rainbow.rb', line 66

def blink
  wrap_with_code(TERM_EFFECTS[:blink])
end

#brightObject

Turns on bright/bold for this text.



51
52
53
# File 'lib/rainbow.rb', line 51

def bright
  wrap_with_code(TERM_EFFECTS[:bright])
end

#foreground(color) ⇒ Object Also known as: color, colour

Sets foreground color if this text.



27
28
29
30
31
# File 'lib/rainbow.rb', line 27

def foreground(color)
   color = color.to_sym
   validate_color(color)
   wrap_with_code(TERM_COLORS[color] + 30)
end

#hideObject

Hides this text (set its color to the same as background).



76
77
78
# File 'lib/rainbow.rb', line 76

def hide
  wrap_with_code(TERM_EFFECTS[:hide])
end

#inverseObject

Inverses current foreground/background colors.



71
72
73
# File 'lib/rainbow.rb', line 71

def inverse
  wrap_with_code(TERM_EFFECTS[:inverse])
end

#italicObject

Turns on italic style for this text (not well supported by terminal emulators).



56
57
58
# File 'lib/rainbow.rb', line 56

def italic
  wrap_with_code(TERM_EFFECTS[:italic])
end

#resetObject

Resets terminal to default colors/backgrounds.

It shouldn’t be needed to use this method because all methods append terminal reset code to end of string.



46
47
48
# File 'lib/rainbow.rb', line 46

def reset
  wrap_with_code(TERM_EFFECTS[:reset])
end

#underlineObject

Turns on underline decoration for this text.



61
62
63
# File 'lib/rainbow.rb', line 61

def underline
  wrap_with_code(TERM_EFFECTS[:underline])
end