From: Gordon Thiesfeld Date: 2010-03-11T12:24:11+09:00 Subject: Re: win32console 1.3.0.beta2 Released On Wed, Mar 10, 2010 at 6:00 PM, Luis Lavena wrote: > On Mar 10, 3:40 pm, Gordon Thiesfeld wrote: >> On Wed, Mar 10, 2010 at 2:35 AM, Luis Lavena wrote: >> > ==== >> >> > Stops there, all without colors. >> >> > Now, running rake spec or spec -c spec display all colors too, so is >> > something around autospec/autotest and Ruby 1.9 >> >> > ==== >> >> > Hope I explained better this time since seems nobody answered on RSpec- >> > dev maybe my english wasn't good enough. >> >> Ah! I see the problem now.  I'm afraid it is in win32console[1], and >> I'm afraid I wrote it. >> This code will reproduce the bug: >> >> ruby -e "require 'rubygems'; require 'win32console'; %Q{\e[31mred\e[0m >> \e[32mgreen\e[0m}.each_byte{|i| putc >> i }" >> >> ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32] >> red green >>  # in color >> >> ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32] >> red green >>  # in color >> >> ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32] >>  [31mred [0m  [32mgreen [0m >> >> Autotest uses getc to read from stdout, and putc to write to it.  I >> redefined Kernel#putc to cache escape codes and write them all at >> once.  Otherwise, win32console won't work.  The problem in 1.9 is that >> "?\e" doesn't return the byte value, but the string.  I'll submit a >> patch. >> >> [1]http://github.com/luislavena/win32console/blob/master/lib/Win32/Conso... >> > > Gordon, your patch fix the issue with red/green sample, but still > generates ANSI codes when running under 1.9.1 with autospec. > > I just cleared all the previous versions of win32console due buggy > load path of 1.9 and still see the same issue. > > The positive side is that the specs now completes instead of > prematurely terminate itself. > > Adding this to either project .autospec file or ~/.autospec file: > > %Q{\e[31mred\e[0m \e[32mgreen\e[0m}.each_byte{|i| putc i } > > Produces colored output, while adding to spec_helper.rb or any of the > files being evaluated inside autospec returns ANSI color codes. > > -- > Luis Lavena > > My patch didn't fix the whole problem. I was assuming that the argument to putc would always be an integer, but apparently in 1.9 it can be an integer or a string. I'll send you another pull request. I tested with autospec this time on 1.8.6, 1.8.7, and 1.9.1.