module Bones::Colors
Constants
- COLORS
Public Instance Methods
colorize( string, *colors )
click to toggle source
This method provides easy access to ANSI color sequences, without the user needing to remember to CLEAR at the end of each sequence. Just pass the string to color, followed by a list of colors you would like it to be affected by. The colors can be class constants, or symbols (:blue for BLUE, for example). A CLEAR will automatically be embedded to the end of the returned String.
This method returns the original string unchanged if colorize? is
false
.
# File lib/bones/colors.rb, line 52 def colorize( string, *colors ) return string unless colorize? colors.map! { |c| c.is_a?(Symbol) ? COLORS[c] : c } "#{colors.flatten.join}#{string}#{COLORS[:clear]}" end
colorize?()
click to toggle source
Returns true if Bones is currently using color escapes.
# File lib/bones/colors.rb, line 63 def colorize? Bones.config.colorize end