Class: Rainbow::Presenter
Constant Summary collapse
- TERM_EFFECTS =
{ reset: 0, bright: 1, faint: 2, italic: 3, underline: 4, blink: 5, inverse: 7, hide: 8, cross_out: 9 }.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.
- #cross_out ⇒ Object (also: #strike)
- #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.
126 127 128 129 130 131 132 |
# File 'lib/rainbow/presenter.rb', line 126 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.
30 31 32 |
# File 'lib/rainbow/presenter.rb', line 30 def background(*values) wrap_with_sgr(Color.build(:background, values).codes) end |
#black ⇒ Object
92 93 94 |
# File 'lib/rainbow/presenter.rb', line 92 def black color(:black) end |
#blink ⇒ Object
Turns on blinking attribute for this text (not well supported by terminal emulators).
72 73 74 |
# File 'lib/rainbow/presenter.rb', line 72 def blink wrap_with_sgr(TERM_EFFECTS[:blink]) end |
#blue ⇒ Object
108 109 110 |
# File 'lib/rainbow/presenter.rb', line 108 def blue color(:blue) end |
#bright ⇒ Object Also known as: bold
Turns on bright/bold for this text.
45 46 47 |
# File 'lib/rainbow/presenter.rb', line 45 def bright wrap_with_sgr(TERM_EFFECTS[:bright]) end |
#color(*values) ⇒ Object Also known as: foreground, fg
Sets color of this text.
22 23 24 |
# File 'lib/rainbow/presenter.rb', line 22 def color(*values) wrap_with_sgr(Color.build(:foreground, values).codes) end |
#cross_out ⇒ Object Also known as: strike
86 87 88 |
# File 'lib/rainbow/presenter.rb', line 86 def cross_out wrap_with_sgr(TERM_EFFECTS[:cross_out]) end |
#cyan ⇒ Object
116 117 118 |
# File 'lib/rainbow/presenter.rb', line 116 def cyan color(:cyan) end |
#faint ⇒ Object Also known as: dark
Turns on faint/dark for this text (not well supported by terminal emulators).
53 54 55 |
# File 'lib/rainbow/presenter.rb', line 53 def faint wrap_with_sgr(TERM_EFFECTS[:faint]) end |
#green ⇒ Object
100 101 102 |
# File 'lib/rainbow/presenter.rb', line 100 def green color(:green) end |
#hide ⇒ Object
Hides this text (set its color to the same as background).
82 83 84 |
# File 'lib/rainbow/presenter.rb', line 82 def hide wrap_with_sgr(TERM_EFFECTS[:hide]) end |
#inverse ⇒ Object
Inverses current foreground/background colors.
77 78 79 |
# File 'lib/rainbow/presenter.rb', line 77 def inverse wrap_with_sgr(TERM_EFFECTS[:inverse]) end |
#italic ⇒ Object
Turns on italic style for this text (not well supported by terminal emulators).
61 62 63 |
# File 'lib/rainbow/presenter.rb', line 61 def italic wrap_with_sgr(TERM_EFFECTS[:italic]) end |
#magenta ⇒ Object
112 113 114 |
# File 'lib/rainbow/presenter.rb', line 112 def magenta color(:magenta) end |
#red ⇒ Object
96 97 98 |
# File 'lib/rainbow/presenter.rb', line 96 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.
40 41 42 |
# File 'lib/rainbow/presenter.rb', line 40 def reset wrap_with_sgr(TERM_EFFECTS[:reset]) end |
#respond_to_missing?(method_name, *args) ⇒ Boolean
134 135 136 |
# File 'lib/rainbow/presenter.rb', line 134 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.
66 67 68 |
# File 'lib/rainbow/presenter.rb', line 66 def underline wrap_with_sgr(TERM_EFFECTS[:underline]) end |
#white ⇒ Object
120 121 122 |
# File 'lib/rainbow/presenter.rb', line 120 def white color(:white) end |
#yellow ⇒ Object
104 105 106 |
# File 'lib/rainbow/presenter.rb', line 104 def yellow color(:yellow) end |