WindowsでRailsのログをカラー表示する

ないはずがないと思っていたが、やっぱりあった。

先日調べたときは見つけられなかったんだけど、今日たまたまRubyist Magazine - スはスペックのス 【第 1 回】 RSpec の概要と、RSpec on Rails (モデル編)を読もうとして発見。いますぐ gem install win32console するべし。

script/server で win32console を使う

gems/rails-2.0.2/lib/commands/servers/base.rb の先頭に

require 'win32/console/ansi'

ついでに、ログをUTF8で残している人は12行目を

-          print contents
+         print NKF.nkf('-s', contents)

としておくとよいだろう。

標準の autotest で win32console を使う

RSpecの場合は上記リンクをみてもらうとして、標準のautotest(Test::Unit)でredgreenしたい場合は、ホームディレクトリかRAILS_ROOTに.autotestを作り、

require 'win32/console/ansi'
require 'redgreen'

とするとよい。redgreen がまだの人は gem install redgreen で。