Class: Rainbow::Presenter
- Inherits:
-
String
- Object
- String
- Rainbow::Presenter
- 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
-
#background(*values) ⇒ Object
(also: #bg)
Sets background color of this text.
- #black ⇒ Object
-
#blink ⇒ Object
Turns on blinking attribute for this text (not well supported by terminal emulators).
- #blue ⇒ Object
-
#bright ⇒ Object
(also: #bold)
Turns on bright/bold for this text.
-
#color(*values) ⇒ Object
(also: #foreground, #fg)
Sets color of this text.
- #cyan ⇒ Object
- #green ⇒ Object
-
#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).
- #magenta ⇒ Object
-
#method_missing(method_name, *args) ⇒ Object
We take care of X11 color method call here.
- #red ⇒ Object
-
#reset ⇒ Object
Resets terminal to default colors/backgrounds.
-
#underline ⇒ Object
Turns on underline decoration for this text.
- #white ⇒ Object
- #yellow ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
We take care of X11 color method call here. Such as #aqua, #ghostwhite.
110 111 112 113 114 115 116 |
# File 'lib/rainbow/presenter.rb', line 110 def method_missing(method_name,*args) if Color::X11Named.color_names.include? method_name and args.empty? then color(method_name) else super end end |
Instance Method Details
#background(*values) ⇒ Object Also known as: bg
Sets background color of this text.
28 29 30 |
# File 'lib/rainbow/presenter.rb', line 28 def background(*values) wrap_with_sgr(Color.build(:background, values).codes) end |
#black ⇒ Object
76 77 78 |
# File 'lib/rainbow/presenter.rb', line 76 def black color(:black) end |
#blink ⇒ Object
Turns on blinking attribute for this text (not well supported by terminal emulators).
62 63 64 |
# File 'lib/rainbow/presenter.rb', line 62 def blink wrap_with_sgr(TERM_EFFECTS[:blink]) end |
#blue ⇒ Object
92 93 94 |
# File 'lib/rainbow/presenter.rb', line 92 def blue color(:blue) end |
#bright ⇒ Object Also known as: bold
Turns on bright/bold for this text.
43 44 45 |
# File 'lib/rainbow/presenter.rb', line 43 def bright wrap_with_sgr(TERM_EFFECTS[:bright]) end |
#color(*values) ⇒ Object Also known as: foreground, fg
Sets color of this text.
20 21 22 |
# File 'lib/rainbow/presenter.rb', line 20 def color(*values) wrap_with_sgr(Color.build(:foreground, values).codes) end |
#cyan ⇒ Object
100 101 102 |
# File 'lib/rainbow/presenter.rb', line 100 def cyan color(:cyan) end |
#green ⇒ Object
84 85 86 |
# File 'lib/rainbow/presenter.rb', line 84 def green color(:green) end |
#hide ⇒ Object
Hides this text (set its color to the same as background).
72 73 74 |
# File 'lib/rainbow/presenter.rb', line 72 def hide wrap_with_sgr(TERM_EFFECTS[:hide]) end |
#inverse ⇒ Object
Inverses current foreground/background colors.
67 68 69 |
# File 'lib/rainbow/presenter.rb', line 67 def inverse wrap_with_sgr(TERM_EFFECTS[:inverse]) end |
#italic ⇒ Object
Turns on italic style for this text (not well supported by terminal emulators).
51 52 53 |
# File 'lib/rainbow/presenter.rb', line 51 def italic wrap_with_sgr(TERM_EFFECTS[:italic]) end |
#magenta ⇒ Object
96 97 98 |
# File 'lib/rainbow/presenter.rb', line 96 def magenta color(:magenta) end |
#red ⇒ Object
80 81 82 |
# File 'lib/rainbow/presenter.rb', line 80 def red color(:red) 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.
38 39 40 |
# File 'lib/rainbow/presenter.rb', line 38 def reset wrap_with_sgr(TERM_EFFECTS[:reset]) end |
#underline ⇒ Object
Turns on underline decoration for this text.
56 57 58 |
# File 'lib/rainbow/presenter.rb', line 56 def underline wrap_with_sgr(TERM_EFFECTS[:underline]) end |
#white ⇒ Object
104 105 106 |
# File 'lib/rainbow/presenter.rb', line 104 def white color(:white) end |
#yellow ⇒ Object
88 89 90 |
# File 'lib/rainbow/presenter.rb', line 88 def yellow color(:yellow) end |