Module | Term::ANSIColor |
In: |
lib/term/ansicolor.rb
|
The ANSIColor module can be used for namespacing and mixed into your own classes.
COLORED_REGEXP | = | /\e\[([34][0-7]|[0-9])m/ | Regular expression that is used to scan for ANSI-sequences while uncoloring strings. |
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 168 168: def self.coloring=(val) 169: @coloring = val 170: end
Returns true, if the coloring function of this module is switched on, false otherwise.
# File lib/term/ansicolor.rb, line 161 161: def self.coloring? 162: @coloring 163: end
Returns an array of all Term::ANSIColor attributes as symbols.
# File lib/term/ansicolor.rb, line 214 214: def attributes 215: ATTRIBUTE_NAMES 216: end
Returns an uncolored version of the string, that is all ANSI-sequences are stripped from the string.
# File lib/term/ansicolor.rb, line 199 199: def uncolored(string = nil) # :yields: 200: if block_given? 201: yield.gsub(COLORED_REGEXP, '') 202: elsif string 203: string.gsub(COLORED_REGEXP, '') 204: elsif respond_to?(:to_str) 205: gsub(COLORED_REGEXP, '') 206: else 207: '' 208: end 209: end