Ruby/ProgressBarをWindowsで使う

高林哲氏のRuby/ProgressBarを、Windowsで使うと以下のようなエラーが出て死んでしまう。

C:\>irb --simple-prompt test.rb
>> require 'test/unit'
=> true
       (中略)
?> >> Loaded suite test
Started
./progressbar.rb:128: [BUG] rb_sys_fail() - errno == 0
ruby 1.8.2 (2004-12-25) [i386-mswin32]

本来であれば例外を発生すべきところなので、Rubyのバグっぽい。
仕方ないので、以下の修正をprogressbar.rbに入れてやることで解決。

 --- progressbar_org.rb  Sun May 22 14:51:40 2005
 +++ progressbar.rb      Fri Oct 14 15:04:28 2005
 @@ -125,7 +125,8 @@
      begin
        tiocgwinsz = 0x5413
        data = [0, 0, 0, 0].pack("SSSS")
 -      if @out.ioctl(tiocgwinsz, data) >= 0 then
 +##      if @out.ioctl(tiocgwinsz, data) >= 0 then
 +      if (RUBY_PLATFORM != "i386-mswin32") && (@out.ioctl(tiocgwinsz, data) >= 0 ) then
          rows, cols, xpixels, ypixels = data.unpack("SSSS")
          if cols >= 0 then cols else default_width end
        else

mingw版やcygwin版とか全然考えていないのであんまり美しくないが、動いたからまあよし。本当は、環境変数でターミナルを調べればいいのかなぁ。