Class: Rainbow::Presenter
- Inherits:
-
String
- Object
- String
- Rainbow::Presenter
- Defined in:
- lib/rainbow/presenter.rb
Constant Summary collapse
- TERM_EFFECTS =
{ reset: 0, bright: 1, faint: 2, 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
-
#faint ⇒ Object
(also: #dark)
Turns on faint/dark for this text (not well supported by terminal emulators).
- #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.
119 120 121 122 123 124 125 |
# File 'lib/rainbow/presenter.rb', line 119 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.
29 30 31 |
# File 'lib/rainbow/presenter.rb', line 29 def background(*values) wrap_with_sgr(Color.build(:background, values).codes) end |
#black ⇒ Object
85 86 87 |
# File 'lib/rainbow/presenter.rb', line 85 def black color(:black) end |
#blink ⇒ Object
Turns on blinking attribute for this text (not well supported by terminal emulators).
71 72 73 |
# File 'lib/rainbow/presenter.rb', line 71 def blink wrap_with_sgr(TERM_EFFECTS[:blink]) end |
#blue ⇒ Object
101 102 103 |
# File 'lib/rainbow/presenter.rb', line 101 def blue color(:blue) end |
#bright ⇒ Object Also known as: bold
Turns on bright/bold for this text.
44 45 46 |
# File 'lib/rainbow/presenter.rb', line 44 def bright wrap_with_sgr(TERM_EFFECTS[:bright]) end |
#color(*values) ⇒ Object Also known as: foreground, fg
Sets color of this text.
21 22 23 |
# File 'lib/rainbow/presenter.rb', line 21 def color(*values) wrap_with_sgr(Color.build(:foreground, values).codes) end |
#cyan ⇒ Object
109 110 111 |
# File 'lib/rainbow/presenter.rb', line 109 def cyan color(:cyan) end |
#faint ⇒ Object Also known as: dark
Turns on faint/dark for this text (not well supported by terminal emulators).
52 53 54 |
# File 'lib/rainbow/presenter.rb', line 52 def faint wrap_with_sgr(TERM_EFFECTS[:faint]) end |
#green ⇒ Object
93 94 95 |
# File 'lib/rainbow/presenter.rb', line 93 def green color(:green) end |
#hide ⇒ Object
Hides this text (set its color to the same as background).
81 82 83 |
# File 'lib/rainbow/presenter.rb', line 81 def hide wrap_with_sgr(TERM_EFFECTS[:hide]) end |
#inverse ⇒ Object
Inverses current foreground/background colors.
76 77 78 |
# File 'lib/rainbow/presenter.rb', line 76 def inverse wrap_with_sgr(TERM_EFFECTS[:inverse]) end |
#italic ⇒ Object
Turns on italic style for this text (not well supported by terminal emulators).
60 61 62 |
# File 'lib/rainbow/presenter.rb', line 60 def italic wrap_with_sgr(TERM_EFFECTS[:italic]) end |
#magenta ⇒ Object
105 106 107 |
# File 'lib/rainbow/presenter.rb', line 105 def magenta color(:magenta) end |
#red ⇒ Object
89 90 91 |
# File 'lib/rainbow/presenter.rb', line 89 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.
39 40 41 |
# File 'lib/rainbow/presenter.rb', line 39 def reset wrap_with_sgr(TERM_EFFECTS[:reset]) end |
#underline ⇒ Object
Turns on underline decoration for this text.
65 66 67 |
# File 'lib/rainbow/presenter.rb', line 65 def underline wrap_with_sgr(TERM_EFFECTS[:underline]) end |
#white ⇒ Object
113 114 115 |
# File 'lib/rainbow/presenter.rb', line 113 def white color(:white) end |
#yellow ⇒ Object
97 98 99 |
# File 'lib/rainbow/presenter.rb', line 97 def yellow color(:yellow) end |