Class: Rainbow::Presenter

Inherits:
String
  • Object
show all
Defined in:
lib/rainbow/presenter.rb

Constant Summary collapse

TERM_EFFECTS =
{
  :reset     => 0,
  :bright    => 1,
  :italic    => 3,
  :underline => 4,
  :blink     => 5,
  :inverse   => 7,
  :hide      => 8,
}

Instance Method Summary collapse

Instance Method Details

#background(*values) ⇒ Object Also known as: bg

Sets background color of this text.



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

def background(*values)
  wrap_with_sgr(Color.build(:background, values).codes)
end

#blackObject



73
74
75
# File 'lib/rainbow/presenter.rb', line 73

def black
  color(:black)
end

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



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

def blink
  wrap_with_sgr(TERM_EFFECTS[:blink])
end

#blueObject



89
90
91
# File 'lib/rainbow/presenter.rb', line 89

def blue
  color(:blue)
end

#brightObject

Turns on bright/bold for this text.



42
43
44
# File 'lib/rainbow/presenter.rb', line 42

def bright
  wrap_with_sgr(TERM_EFFECTS[:bright])
end

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

Sets color of this text.



19
20
21
# File 'lib/rainbow/presenter.rb', line 19

def color(*values)
  wrap_with_sgr(Color.build(:foreground, values).codes)
end

#cyanObject



97
98
99
# File 'lib/rainbow/presenter.rb', line 97

def cyan
  color(:cyan)
end

#greenObject



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

def green
  color(:green)
end

#hideObject

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



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

def hide
  wrap_with_sgr(TERM_EFFECTS[:hide])
end

#inverseObject

Inverses current foreground/background colors.



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

def inverse
  wrap_with_sgr(TERM_EFFECTS[:inverse])
end

#italicObject

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



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

def italic
  wrap_with_sgr(TERM_EFFECTS[:italic])
end

#magentaObject



93
94
95
# File 'lib/rainbow/presenter.rb', line 93

def magenta
  color(:magenta)
end

#redObject



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

def red
  color(:red)
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.



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

def reset
  wrap_with_sgr(TERM_EFFECTS[:reset])
end

#underlineObject

Turns on underline decoration for this text.



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

def underline
  wrap_with_sgr(TERM_EFFECTS[:underline])
end

#whiteObject



101
102
103
# File 'lib/rainbow/presenter.rb', line 101

def white
  color(:white)
end

#yellowObject



85
86
87
# File 'lib/rainbow/presenter.rb', line 85

def yellow
  color(:yellow)
end