Module: Term::ANSIColorHI
- Extended by:
- ANSIColorHI
- Included in:
- ANSIColorHI
- Defined in:
- lib/term/ansicolorhi.rb,
lib/term/ansicolor/version.rb
Overview
The ANSIColorHI module can be used for namespacing and mixed into your own classes.
Constant Summary collapse
- ATTRIBUTES =
:stopdoc:
[ [ :clear , 0 ], [ :reset , 0 ], # synonym for :clear [ :bold , 1 ], [ :dark , 2 ], [ :italic , 3 ], # not widely implemented [ :underline , 4 ], [ :underscore , 4 ], # synonym for :underline [ :blink , 5 ], [ :rapid_blink , 6 ], # not widely implemented [ :negative , 7 ], # no reverse because of String#reverse [ :concealed , 8 ], [ :strikethrough , 9 ], # not widely implemented [ :black , 30 ], [ :red , 31 ], [ :green , 32 ], [ :yellow , 33 ], [ :blue , 34 ], [ :magenta , 35 ], [ :cyan , 36 ], [ :white , 37 ], [ :on_black , 40 ], [ :on_red , 41 ], [ :on_green , 42 ], [ :on_yellow , 43 ], [ :on_blue , 44 ], [ :on_magenta , 45 ], [ :on_cyan , 46 ], [ :on_white , 47 ], [ :intense_black , 90 ], # High intensity, aixterm (works in OS X) [ :intense_red , 91 ], [ :intense_green , 92 ], [ :intense_yellow , 93 ], [ :intense_blue , 94 ], [ :intense_magenta , 95 ], [ :intense_cyan , 96 ], [ :intense_white , 97 ], [ :on_intense_black , 100 ], # High intensity background, aixterm (works in OS X) [ :on_intense_red , 101 ], [ :on_intense_green , 102 ], [ :on_intense_yellow , 103 ], [ :on_intense_blue , 104 ], [ :on_intense_magenta , 105 ], [ :on_intense_cyan , 106 ], [ :on_intense_white , 107 ] ]
- ATTRIBUTE_NAMES =
ATTRIBUTES.transpose.first
- COLORED_REGEXP =
Regular expression that is used to scan for ANSI-sequences while uncoloring strings.
/\e\[(?:[34][0-7]|[0-9])?m/
- VERSION =
Term::ANSIColorHI version
'1.0.7'
- VERSION_ARRAY =
:nodoc:
VERSION.split(/\./).map { |x| x.to_i }
- VERSION_MAJOR =
:nodoc:
VERSION_ARRAY[0]
- VERSION_MINOR =
:nodoc:
VERSION_ARRAY[1]
- VERSION_BUILD =
:nodoc:
VERSION_ARRAY[2]
Class Method Summary collapse
-
.attributes ⇒ Object
Returns an array of all Term::ANSIColorHI attributes as symbols.
-
.coloring=(val) ⇒ Object
Turns the coloring on or off globally, so you can easily do this for example: Term::ANSIColorHI::coloring = STDOUT.isatty.
-
.coloring? ⇒ Boolean
Returns true, if the coloring function of this module is switched on, false otherwise.
Instance Method Summary collapse
-
#uncolored(string = nil) ⇒ Object
Returns an uncolored version of the string, that is all ANSI-sequences are stripped from the string.
Class Method Details
.attributes ⇒ Object
Returns an array of all Term::ANSIColorHI attributes as symbols.
113 114 115 |
# File 'lib/term/ansicolorhi.rb', line 113 def attributes ATTRIBUTE_NAMES end |
.coloring=(val) ⇒ Object
Turns the coloring on or off globally, so you can easily do this for example:
Term::ANSIColorHI::coloring = STDOUT.isatty
67 68 69 |
# File 'lib/term/ansicolorhi.rb', line 67 def self.coloring=(val) @coloring = val end |
.coloring? ⇒ Boolean
Returns true, if the coloring function of this module is switched on, false otherwise.
60 61 62 |
# File 'lib/term/ansicolorhi.rb', line 60 def self.coloring? @coloring end |
Instance Method Details
#uncolored(string = nil) ⇒ Object
Returns an uncolored version of the string, that is all ANSI-sequences are stripped from the string.
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/term/ansicolorhi.rb', line 98 def uncolored(string = nil) # :yields: 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 |