Module: Kat::Colour
Constant Summary collapse
- COLOURS =
%w(black red green yellow blue magenta cyan white)- @@colour =
capable?
Class Method Summary collapse
-
.capable? ⇒ Boolean
From AwesomePrint.colorize? by Michael Dvorkin github.com/michaeldv/awesome_print/blob/master/lib/awesome_print/inspector.rb.
- .colour=(f) ⇒ Object
- .colour? ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.capable? ⇒ Boolean
From AwesomePrint.colorize? by Michael Dvorkin github.com/michaeldv/awesome_print/blob/master/lib/awesome_print/inspector.rb
7 8 9 |
# File 'lib/kat/colour.rb', line 7 def self.capable? STDOUT.tty? && (ENV['TERM'] && ENV['TERM'] != 'dumb' || ENV['ANSICON']) end |
.colour=(f) ⇒ Object
11 12 13 |
# File 'lib/kat/colour.rb', line 11 def self.colour=(f) @@colour = f && capable? end |
.colour? ⇒ Boolean
15 16 17 |
# File 'lib/kat/colour.rb', line 15 def self.colour? @@colour end |
Instance Method Details
#colour? ⇒ Boolean
21 22 23 |
# File 'lib/kat/colour.rb', line 21 def colour? @@colour end |
#uncolour ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/kat/colour.rb', line 30 def uncolour case self when String then gsub(/\e\[[0-9;]+?m(.*?)\e\[0m/, '\\1') when Array then map { |e| e.uncolour if e } else self end end |
#uncolour! ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/kat/colour.rb', line 38 def uncolour! case self when String then replace uncolour when Array then each { |e| e.uncolour! if e } end self end |