class FoodCritic::ContextOutput

def ansi_print(text, fg, bg = nil, attr = nil)

Parameters:
  • attr (String) -- any formatting options
  • bg (String) -- background color
  • fg (String) -- foreground color
  • text (String) -- the string to format
def ansi_print(text, fg, bg = nil, attr = nil)
  unless @out.tty?
    puts text
    return
  end
  colors = %w{black red green yellow blue magenta cyan white}
  attrs = %w{reset bold dim underscore blink reverse hidden}
  escape = "\033[%sm"
  fmt = []
  fmt << 30 + colors.index(fg.to_s) if fg
  fmt << 40 + colors.index(bg.to_s) if bg
  fmt << attrs.index(attr.to_s) if attr
  if fmt
    puts "#{escape % fmt.join(";")}#{text}#{escape % 0}"
  else
    puts text
  end
end