The ANSIColor module can be used for namespacing and mixed into your own classes.
Regular expression that is used to scan for ANSI-sequences while uncoloring strings.
Term::ANSIColor version
Turns the coloring on or off globally, so you can easily do this for example:
Term::ANSIColor::coloring = STDOUT.isatty
# File lib/term/ansicolor.rb, line 80 def self.coloring=(val) @coloring = val end
Returns true, if the coloring function of this module is switched on, false otherwise.
# File lib/term/ansicolor.rb, line 73 def self.coloring? @coloring end
Returns an array of all Term::ANSIColor attributes as symbols.
# File lib/term/ansicolor.rb, line 126 def attributes ATTRIBUTE_NAMES end
Returns true if Term::ANSIColor supports the
feature
.
The feature :clear, that is mixing the clear color attribute into String, is only supported on ruby implementations, that do not already implement the String#clear method. It's better to use the reset color attribute instead.
# File lib/term/ansicolor.rb, line 65 def support?(feature) case feature when :clear !String.instance_methods(false).map(&:to_sym).include?(:clear) end end
Returns an uncolored version of the string, that is all ANSI-sequences are stripped from the string.
# File lib/term/ansicolor.rb, line 111 def uncolored(string = nil) # :yields: if block_given? yield.to_str.gsub(COLORED_REGEXP, '') elsif string.respond_to?(:to_str) string.to_str.gsub(COLORED_REGEXP, '') elsif respond_to?(:to_str) to_str.gsub(COLORED_REGEXP, '') else '' end end