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 }.freeze
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.
- #respond_to_missing?(method_name, *args) ⇒ Boolean
-
#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.
117 118 119 120 121 122 123 |
# File 'lib/rainbow/presenter.rb', line 117 def method_missing(method_name, *args) if Color::X11Named.color_names.include?(method_name) && args.empty? color(method_name) else super end end |
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 |
#black ⇒ Object
83 84 85 |
# File 'lib/rainbow/presenter.rb', line 83 def black color(:black) end |
#blink ⇒ Object
Turns on blinking attribute for this text (not well supported by terminal emulators).
69 70 71 |
# File 'lib/rainbow/presenter.rb', line 69 def blink wrap_with_sgr(TERM_EFFECTS[:blink]) end |
#blue ⇒ Object
99 100 101 |
# File 'lib/rainbow/presenter.rb', line 99 def blue color(:blue) end |
#bright ⇒ Object Also known as: bold
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 |
#cyan ⇒ Object
107 108 109 |
# File 'lib/rainbow/presenter.rb', line 107 def cyan color(:cyan) end |
#faint ⇒ Object Also known as: dark
Turns on faint/dark for this text (not well supported by terminal emulators).
50 51 52 |
# File 'lib/rainbow/presenter.rb', line 50 def faint wrap_with_sgr(TERM_EFFECTS[:faint]) end |
#green ⇒ Object
91 92 93 |
# File 'lib/rainbow/presenter.rb', line 91 def green color(:green) end |
#hide ⇒ Object
Hides this text (set its color to the same as background).
79 80 81 |
# File 'lib/rainbow/presenter.rb', line 79 def hide wrap_with_sgr(TERM_EFFECTS[:hide]) end |
#inverse ⇒ Object
Inverses current foreground/background colors.
74 75 76 |
# File 'lib/rainbow/presenter.rb', line 74 def inverse wrap_with_sgr(TERM_EFFECTS[:inverse]) end |
#italic ⇒ Object
Turns on italic style for this text (not well supported by terminal emulators).
58 59 60 |
# File 'lib/rainbow/presenter.rb', line 58 def italic wrap_with_sgr(TERM_EFFECTS[:italic]) end |
#magenta ⇒ Object
103 104 105 |
# File 'lib/rainbow/presenter.rb', line 103 def magenta color(:magenta) end |
#red ⇒ Object
87 88 89 |
# File 'lib/rainbow/presenter.rb', line 87 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.
37 38 39 |
# File 'lib/rainbow/presenter.rb', line 37 def reset wrap_with_sgr(TERM_EFFECTS[:reset]) end |
#respond_to_missing?(method_name, *args) ⇒ Boolean
125 126 127 |
# File 'lib/rainbow/presenter.rb', line 125 def respond_to_missing?(method_name, *args) Color::X11Named.color_names.include?(method_name) && args.empty? || super end |
#underline ⇒ Object
Turns on underline decoration for this text.
63 64 65 |
# File 'lib/rainbow/presenter.rb', line 63 def underline wrap_with_sgr(TERM_EFFECTS[:underline]) end |
#white ⇒ Object
111 112 113 |
# File 'lib/rainbow/presenter.rb', line 111 def white color(:white) end |
#yellow ⇒ Object
95 96 97 |
# File 'lib/rainbow/presenter.rb', line 95 def yellow color(:yellow) end |