Module: Kat::Colour

Included in:
Array, String, Symbol
Defined in:
lib/kat/colour.rb

Constant Summary collapse

COLOURS =
%w(black red green yellow blue magenta cyan white)
@@colour =
capable?

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.capable?Boolean

Returns:



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

Returns:



15
16
17
# File 'lib/kat/colour.rb', line 15

def self.colour?
  @@colour
end

Instance Method Details

#colour?Boolean

Returns:



21
22
23
# File 'lib/kat/colour.rb', line 21

def colour?
  @@colour
end

#uncolourObject



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