Module: Sickill::Rainbow

Defined in:
lib/rainbow.rb,
lib/ansi_rgb.rb,
lib/ansi_color.rb

Defined Under Namespace

Classes: AnsiColor, AnsiRgb, RGB

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,
}

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.enabledObject

Returns the value of attribute enabled.



6
7
8
# File 'lib/rainbow.rb', line 6

def enabled
  @enabled
end

Instance Method Details

#background(*color) ⇒ Object

Sets background color of this text.



40
41
42
# File 'lib/rainbow.rb', line 40

def background(*color)
  wrap_with_code(AnsiColor.new(:background, *color).code)
end

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



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

def blink
  wrap_with_code(TERM_EFFECTS[:blink])
end

#brightObject

Turns on bright/bold for this text.



53
54
55
# File 'lib/rainbow.rb', line 53

def bright
  wrap_with_code(TERM_EFFECTS[:bright])
end

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

Sets foreground color of this text.



32
33
34
# File 'lib/rainbow.rb', line 32

def foreground(*color)
  wrap_with_code(AnsiColor.new(:foreground, *color).code)
end

#hideObject

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



80
81
82
# File 'lib/rainbow.rb', line 80

def hide
  wrap_with_code(TERM_EFFECTS[:hide])
end

#inverseObject

Inverses current foreground/background colors.



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

def inverse
  wrap_with_code(TERM_EFFECTS[:inverse])
end

#italicObject

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



59
60
61
# File 'lib/rainbow.rb', line 59

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.



48
49
50
# File 'lib/rainbow.rb', line 48

def reset
  wrap_with_code(TERM_EFFECTS[:reset])
end

#underlineObject

Turns on underline decoration for this text.



64
65
66
# File 'lib/rainbow.rb', line 64

def underline
  wrap_with_code(TERM_EFFECTS[:underline])
end