Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/clive/output.rb
Constant Summary collapse
- COLOURS =
{ "black" => 0, "red" => 1, "green" => 2, "yellow" => 3, "blue" => 4, "magenta" => 5, "cyan" => 6, "white" => 7 }
- ATTRIBUTES =
{ "bold" => 1, "underline" => 4, "blink" => 5, "reverse" => 7 }
Instance Method Summary collapse
-
#clear_colours ⇒ Object
Remove any colour codes from a string.
-
#clear_colours! ⇒ Object
Same as #clear_colours, but modifies string.
- #colour(code) ⇒ Object
-
#colour!(code) ⇒ Object
Like #colour but modifies the string object.
Instance Method Details
#clear_colours ⇒ Object
Remove any colour codes from a string.
132 133 134 |
# File 'lib/clive/output.rb', line 132 def clear_colours gsub /\e\[?\d\d{0,2}m/, '' end |
#clear_colours! ⇒ Object
Same as #clear_colours, but modifies string.
137 138 139 |
# File 'lib/clive/output.rb', line 137 def clear_colours! gsub! /\e\[?\d\d{0,2}m/, '' end |
#colour(code) ⇒ Object
120 121 122 123 124 |
# File 'lib/clive/output.rb', line 120 def colour(code) r = "\e[#{code}m#{self}" r << "\e[0m" unless self[-4..-1] == "\e[0m" r end |
#colour!(code) ⇒ Object
Like #colour but modifies the string object.
127 128 129 |
# File 'lib/clive/output.rb', line 127 def colour!(code) replace self.colour(code) end |