INNER CODE UNIT · Ruby
initialize
capistrano/sshkit · lib/sshkit/color.rb:26
def initialize(output, env=ENV)
@output, @env = output, env
end
# Converts the given obj to string and surrounds in the appropriate ANSI
# color escape sequence, based on the specified color and mode. The color
# must be a symbol (see COLOR_CODES for a complete list).
#
# If the underlying output does not support ANSI color (see `colorize?),
# the string will be not be colorized. Likewise if the specified color
# symbol is unrecognized, the string will not be colorized.
#
# Note that the only mode currently support is :bold. All other values
# will be silently ignored (i.e. treated the same as mode=nil).
#
def colorize(obj, color, mode=nil)
string = obj.to_s
return string unless colorize?