class Thor::Shell::Color


Thor::Shell::Basic to see all available methods.
Inherit from Thor::Shell::Basic and add set_color behavior. Check

def are_colors_disabled?

def are_colors_disabled?
  !ENV["NO_COLOR"].nil? && !ENV["NO_COLOR"].empty?
end

def are_colors_supported?

def are_colors_supported?
  stdout.tty? && ENV["TERM"] != "dumb"
end

def can_display_colors?

def can_display_colors?
  are_colors_supported? && !are_colors_disabled?
end

def set_color(string, *colors)

:on_white
:on_cyan
:on_magenta
:on_blue
:on_yellow
:on_green
:on_red
:on_black
:white
:cyan
:magenta
:blue
:yellow
:green
:red
:black
:bold

The available colors are:

set_color "Hi!", :red, :on_white, :bold

Example:

symbols.
Pass foreground, background and bold options to this method as

of the returned String.
on Highline implementation and it automatically appends CLEAR to the end
option is set to true, it also adds bold to the string. This is based
Set color by using a string or one of the defined constants. If a third
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