I've been writing a lot of rake tasks lately. I like to have a lot of output (feedback) from my tasks, at least while I'm writing them. I have colors in my tests, but my output is really ugly, so I took some code from Chatte, - a simple chat application a friend (and awesome developer) wrote for college- and made some modifications for it. Here's my module right now...

# https://gist.github.com/nhocki/1410582
module Colors
  def colorize(text, color_code)
    "\033[#{color_code}m#{text}\033[0m"
  end

  {
    :black    => 30,
    :red      => 31,
    :green    => 32,
    :yellow   => 33,
    :blue     => 34,
    :magenta  => 35,
    :cyan     => 36,
    :white    => 37
  }.each do |key, color_code|
    define_method key do |text|
      colorize(text, color_code)
    end
  end
end

# green "Hello"
#   => "\e[32mHello\e[0m"

Now, you just need to include Colors in your tasks and enjoy your life.

I know there's a colorize gem out there, but I don't like their syntax. I prefer Andres' approach much more, so maybe I'll turn this into a really simple gem. Do you think it's worth it?