This method is only available on newer versions.
The first available version (v2_6_3) is shown here.
set_color(string, *colors)
public
Set color by using a string or one of the defined
constants. If a third option is set to true, it also adds bold to the
string. This is based on Highline implementation and it automatically
appends CLEAR to the end of the returned String.
Pass foreground, background and bold options to this method as symbols.
# File lib/bundler/vendor/thor/lib/thor/shell/color.rb, line 79
def set_color(string, *colors)
if colors.compact.empty? || !can_display_colors?
string
elsif colors.all? { |color| color.is_a?(Symbol) || color.is_a?(String) }
ansi_colors = colors.map { |color| lookup_color(color) }
"#{ansi_colors.join}#{string}#{CLEAR}"
else
# The old API was `set_color(color, bold=boolean)`. We
# continue to support the old API because you should never
# break old APIs unnecessarily :P
foreground, bold = colors
foreground = self.class.const_get(foreground.to_s.upcase) if foreground.is_a?(Symbol)
bold = bold ? BOLD : ""
"#{bold}#{foreground}#{string}#{CLEAR}"
end
end