Module: Sickill::Rainbow
- Defined in:
- lib/wrong/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, }
Class Attribute Summary collapse
-
.enabled ⇒ Object
Returns the value of attribute enabled.
Instance Method Summary collapse
-
#background(*color) ⇒ Object
Sets background color of this text.
-
#blink ⇒ Object
Turns on blinking attribute for this text (not well supported by terminal emulators).
-
#bright ⇒ Object
(also: #bold)
Turns on bright/bold for this text.
-
#foreground(*color) ⇒ Object
(also: #color, #colour)
Sets foreground color of this text.
-
#hide ⇒ Object
Hides this text (set its color to the same as background).
-
#inverse ⇒ Object
Inverses current foreground/background colors.
-
#italic ⇒ Object
Turns on italic style for this text (not well supported by terminal emulators).
-
#reset ⇒ Object
Resets terminal to default colors/backgrounds.
-
#underline ⇒ Object
Turns on underline decoration for this text.
Class Attribute Details
.enabled ⇒ Object
Returns the value of attribute enabled.
5 6 7 |
# File 'lib/wrong/rainbow.rb', line 5 def enabled @enabled end |
Instance Method Details
#background(*color) ⇒ Object
Sets background color of this text.
39 40 41 42 |
# File 'lib/wrong/rainbow.rb', line 39 def background(*color) color = color.first if color.size == 1 wrap_with_code(get_color_code(color, :background)) end |
#blink ⇒ Object
Turns on blinking attribute for this text (not well supported by terminal emulators).
68 69 70 |
# File 'lib/wrong/rainbow.rb', line 68 def blink wrap_with_code(TERM_EFFECTS[:blink]) end |
#bright ⇒ Object Also known as: bold
Turns on bright/bold for this text.
52 53 54 |
# File 'lib/wrong/rainbow.rb', line 52 def bright wrap_with_code(TERM_EFFECTS[:bright]) end |
#foreground(*color) ⇒ Object Also known as: color, colour
Sets foreground color of this text.
31 32 33 34 |
# File 'lib/wrong/rainbow.rb', line 31 def foreground(*color) color = color.first if color.size == 1 wrap_with_code(get_color_code(color, :foreground)) end |
#hide ⇒ Object
Hides this text (set its color to the same as background).
78 79 80 |
# File 'lib/wrong/rainbow.rb', line 78 def hide wrap_with_code(TERM_EFFECTS[:hide]) end |
#inverse ⇒ Object
Inverses current foreground/background colors.
73 74 75 |
# File 'lib/wrong/rainbow.rb', line 73 def inverse wrap_with_code(TERM_EFFECTS[:inverse]) end |
#italic ⇒ Object
Turns on italic style for this text (not well supported by terminal emulators).
58 59 60 |
# File 'lib/wrong/rainbow.rb', line 58 def italic wrap_with_code(TERM_EFFECTS[:italic]) end |
#reset ⇒ Object
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.
47 48 49 |
# File 'lib/wrong/rainbow.rb', line 47 def reset wrap_with_code(TERM_EFFECTS[:reset]) end |
#underline ⇒ Object
Turns on underline decoration for this text.
63 64 65 |
# File 'lib/wrong/rainbow.rb', line 63 def underline wrap_with_code(TERM_EFFECTS[:underline]) end |