Ruby could use a bit more color. We’re all clamoring for it. Coloring our tests. Tagging our log files. Here’s some quick (and/or dirty) help.
$ sudo gem install colored
Launch yourself an irb and try ‘er out:
Fun stuff (pretend it says colored, not color for the require). Not just for the console, though—it also works in Rails log files.
logger.debug "API: ".red.bold + "Got topics from Chowhound.".red
becomes
And hey, Windows users?
$ gem install win32console
It works, thanks to lucas for testing and Dr Nic for the gemified version of Win32Console.
Here’s a short screencast (it’s so fast that it appears static):
Have fun.
This reminds me of some code I worked on in Heretix. We did the same thing for Ruby strings.. though it had a few quirks.
Now we have a nice packaged gem! Thanks.
I had made something very similar myself for personal use. Very cool stuff. Any chance we can get this working with zentest?
PS: Just noticed the example as i’m watching battlestar galactica… hrm. ponderous, indeed. :)
Anyone have this problem?
Local gem file not found: color*.gem Attempting remote installation of ‘color’ Updating Gem source index for: require.errtheblog.com ERROR: While executing gem … (TypeError) can’t convert Hash into String
“screencast” – you are so web2.0. :)
Of course, there’s already the Text::Highlight gem. But that’s no fun.
Win32Console is already gemified – just install win32console. No need to go to another gem repository.
It’s a different project than Gonzales, but uses his code:
http://rubyforge.org/projects/winconsole/
autotest can use the redgreen gem to do this…
Textile mangled my code…
Anyway, there is already a color gem. Maybe a different name could be used?
http://rubyforge.org/projects/color/
Hope this will be of some use.
I wrote up some code to colorize your test suite that is run by rake. I wanted to run all my test and have the output be colorized without much work, so rather than hacking the ruby test libs I just re-opened them a little.
Here is the url: http://www.nkryptic.com/2006/10/26/rails-colorized-rake-testing
For irb-specific coloring, check out http://pablotron.org/software/wirble/
FYI, in the States, “colored” can be a charged term, so beware.
Yes, beware, I as a computer know of such prejudices of color. Deep Blue? I’m actually quite cheery and my aluminum and silicon parts are neither deep, nor blue.
In the screenshot it still says gem install color and require colo@r. To get it working change both to @colored
I failed to get it working with Windows too, but after 20 minutes of inspecting how redgreen works, I could get it to work. My solution doesn’t require any external gems or plugins, but it does pollute your test_helper even more. Maybe I should convert it to plugin some day and take use of redgreen.
if ENV[‘COLORIZE’] || ENV[‘TERM’] == ‘linux’ require ‘test/unit’ require ‘test/unit/ui/console/testrunner’ end
Chime in.