Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 0.38 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # http://travelingfrontiers.wordpress.com/2010/08/22/how-to-add-colors-to-linux-command-line-output/
  2.  
  3. def color_text(text, color, bold = false)
  4.   colors = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
  5.   if $stdout.isatty && colors.include?(color.to_sym)
  6.     format("\033[%d;%dm%s\033[0m", (bold ? 1 : 0), colors.index(color.to_sym)+30, text)
  7.   else
  8.     text
  9.   end
  10. end