module Lucid::Term::ANSIColor

Constants

ATTRIBUTES
ATTRIBUTE_NAMES
COLORED_REGEXP

Regular expression that is used to scan for ANSI-sequences while there are uncolored strings.

Public Class Methods

coloring=(val) click to toggle source

Example Usage:

Lucid::Term::ANSIColor::coloring = STDOUT.isatty
# File lib/lucid/ansicolor.rb, line 43
def self.coloring=(val)
  @coloring = val
end
coloring?() click to toggle source
# File lib/lucid/ansicolor.rb, line 37
def self.coloring?
  @coloring
end
included(klass) click to toggle source
# File lib/lucid/ansicolor.rb, line 72
def self.included(klass)
  if klass == String
    ATTRIBUTES.delete(:clear)
    ATTRIBUTE_NAMES.delete(:clear)
  end
end

Public Instance Methods

attributes() click to toggle source

Returns an array of all Lucid::Term::ANSIColor attributes as symbols.

# File lib/lucid/ansicolor.rb, line 96
def attributes
  ATTRIBUTE_NAMES
end
uncolored(string = nil) { || ... } click to toggle source

Returns an uncolored version of the string. This means all ANSI-sequences will be stripped from the string.

# File lib/lucid/ansicolor.rb, line 81
def uncolored(string = nil)
  if block_given?
    yield.gsub(COLORED_REGEXP, '')
  elsif string
    string.gsub(COLORED_REGEXP, '')
  elsif respond_to?(:to_str)
    to_str.gsub(COLORED_REGEXP, '')
  else
    ''
  end
end