class Haml::Exec::Generic

def color(color, str)

Returns:
  • (String) - The wrapped string.

Parameters:
  • str (String) -- The string to wrap in the given color.
  • color (Symbol) -- The name of the color to use.
def color(color, str)
  raise "[BUG] Unrecognized color #{color}" unless COLORS[color]
  # Almost any real Unix terminal will support color,
  # so we just filter for Windows terms (which don't set TERM)
  # and not-real terminals, which aren't ttys.
  return str if ENV["TERM"].nil? || ENV["TERM"].empty? || !STDOUT.tty?
  return "\e[#{COLORS[color]}m#{str}\e[0m"
end