As you might know, Windows lacks support for ANSI color sequences. To
workaround this limitation, several languages created their tools that
catch and transform these color sequences into Win32API console calls.
Background:
In Ruby land, win32console was a port of Win32::Console from perl [1]
by Gonzalo Garramuno
In May 2008 I took the work from Justin Bailey [2] and upgrade the
infrastructure to properly support the MinGW work for RubyInstaller
and migrated it to GitHub [3]
Projects like RSpec and Cucumber which depends on ANSI color sequence
implemented workarounds to use them.
While the project had its limitations, it serve it's purpose.
Issues:
Moving forward to Ruby 1.9, the need for accented characters generated
a lot of issues for those colored codes under Windows. Just looking at
Cucumber troubleshooting page [4] indicates how big the issue was
(and still is for some users)
A few weeks back some users reported issues related to autotest not
properly escaping the colors [5]. Investigated into the issue and
found that autotest is outputting the ANSI escape sequence byte at
byte, which confused win32console and made it ignore them.
Proposal:
While working on a win32console (crayons). Another user approached me
telling me of similar issues under JRuby and cucumber. He found
ANSICON [6] and tested with good results.
I remember playing with it back in Jan 2009 but it failed to work
under 64bits systems so discarded it.
Seems that Jason Hood not only upgraded it to work under 64bits
systems, but also made it possible inject it as permanent AutoRun
clause, so every new open console will be ANSI capable.
I've discussed with Gordon Thiesfeld (contributor of win32console),
and we both agree that performance wise [7] the usage of ANSICON looks
better than the Ruby implementation.
Also, seems it will be possible simplify the code RSpec and Cucumber
do in order to deal with ANSI coloring on Windows independently of the
Ruby implementation running.
So far during testing and small modifications to the above mentioned
libraries, it performed well and sensibly faster than win32console
(the bigger spec/features set you have, the better)
People that knows me, can tell how lazy I am... the less libraries I
need to maintain, the more hours of sleep and naps I will be able to
take.
Conclusion:
I believe above provided points are good enough to deprecate
win32console usage, send patches that introduce the changes to these
libraries requiring win32console and advertise/recommend usage of
ANSICON and use ENV['ANSICON'] to check its availability.
Thoughts? Comments? Rejections for this proposal?
[1] http://rubyforge.org/projects/win32console/
[2] http://rubyforge.org/projects/winconsole/
[3] https://github.com/luislavena/win32console/
[4] https://github.com/aslakhellesoy/cucumber/wiki/Troubleshooting
[5] https://github.com/luislavena/win32console/issues#issue/9
[6] http://adoxa.110mb.com/ansicon/index.html
[7] https://gist.github.com/660199
--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry
So long as dropping support for that ANSI colour codes on Win9x is ok
- does COMMAND.COM support showing colours at all, anyway? - I say go
ahead.
Leo
> --
> You received this message because you are subscribed to the Google Groups "RubyInstaller" group.
> To post to this group, send email to rubyin...@googlegroups.com.
> To unsubscribe from this group, send email to rubyinstalle...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyinstaller?hl=en.
>
>
--
Dr Nic Williams
Engine Yard, VP Technology
http://engineyard.com
http://drnicwilliams.com
cell +1 (415) 322-9556
Did you change the codepage after installing ANSICON? (ansicon -p)
Or before?
I haven't checked the code fully but I think it is not possible to get
the current codepage dynamically and only at installation time.
win32console handles it because the ruby process is initialized after
your change and takes the current one instead. On Ruby 1.9 there is
also a lot of encoding things.
I'll take a look later today. Will try to reach Jason Hood to see if
we can get the code at GitHub so it adds more visibility to it and is
more easy to dig and review.
Cheers,
2010/11/3 Boško Ivanišević <bosko.iv...@gmail.com>:
>Did you change the codepage after installing ANSICON? (ansicon -p)
>> [7] https://gist.github.com/660199
>> --
>
> I am also for depricating win32console but at the moment one thing worries
> me - handling UTF-8 characters. Just tried your test [7] and changed letter
> 'E' with some Cyrillic characters, changed active code page to 65001 (utf-8)
> and ansicon printed out a few garbage characters after the original
> sequence. That does not happen in win32console.
> --
Or before?
I haven't checked the code fully but I think it is not possible to get
the current codepage dynamically and only at installation time.
win32console handles it because the ruby process is initialized after
your change and takes the current one instead. On Ruby 1.9 there is
also a lot of encoding things.
I'll take a look later today. Will try to reach Jason Hood to see if
we can get the code at GitHub so it adds more visibility to it and is
more easy to dig and review.
Did you also change the font for the console window?
Works perfectly for me.
--
You received this message because you are subscribed to the Google Groups "RubyInstaller" group.
To post to this group, send email to rubyin...@googlegroups.com.
To unsubscribe from this group, send email to rubyinstalle...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyinstaller?hl=en.
I'm using Consolas and chcp 1252.
Normally "type x.txt" that contains any type of accented characters
ends with garbage in the output, with or without ANSICON.
So, decided to force the encoding when saving the file to Windows-1252
and accents works ok. Ruby 1.8.7 also works, but not 1.9.2:
C:\Users\Luis\Projects\_sandbox>ruby foo.rb
foo.rb:1: invalid multibyte char (US-ASCII)
foo.rb:1: syntax error, unexpected $undefined, expecting $end
puts "\e[33mÉ\e[0msta es una l\e[31mí\e[0mnea de texto."
^
So added a magic comment:
# encoding: Windows-1252
And invoking worked:
C:\Users\Luis\Projects\_sandbox>ruby foo.rb
[33mÉ [0msta es una l [31mí [0mnea de texto.
Now, I enabled ANSICON and it worked (see attached)
So I think garbaged characters might be the consequence of Ruby 1.9.2
and is 'ability' to play with encodings.
Bosko, if you don't mind, I would love to see another example (attach
the files) so I can test it.
Tried to recreate your scenario and of course ended with garbage, but
think is related to incorrect encoding in my source files (Dunno how
to genera Cyrillic characters)
Thank you.
On Thu, Nov 4, 2010 at 11:48 AM, Octagon <g...@kaluga.ru> wrote:I'm using Consolas and chcp 1252.
> Did you also change the font for the console window?
>
> Works perfectly for me.
>
Normally "type x.txt" that contains any type of accented characters
ends with garbage in the output, with or without ANSICON.
So, decided to force the encoding when saving the file to Windows-1252
and accents works ok. Ruby 1.8.7 also works, but not 1.9.2:
C:\Users\Luis\Projects\_sandbox>ruby foo.rb
foo.rb:1: invalid multibyte char (US-ASCII)
foo.rb:1: syntax error, unexpected $undefined, expecting $end
puts "\e[33mÉ\e[0msta es una l\e[31mí\e[0mnea de texto."
^
So added a magic comment:
# encoding: Windows-1252
And invoking worked:
C:\Users\Luis\Projects\_sandbox>ruby foo.rb
[33mÉ [0msta es una l [31mí [0mnea de texto.
Now, I enabled ANSICON and it worked (see attached)
So I think garbaged characters might be the consequence of Ruby 1.9.2
and is 'ability' to play with encodings.
Bosko, if you don't mind, I would love to see another example (attach
the files) so I can test it.
Tried to recreate your scenario and of course ended with garbage, but
think is related to incorrect encoding in my source files (Dunno how
to genera Cyrillic characters)
--
Every time I enable chcp 65001 and do a simple 'type' I get garbled results.
I needed to resave your file with Windows-1251 and set my codepage to
1251 just to be able to have 'type' work properly.
Neither Ruby, ANSICON or win32consoled worked for me. Maybe is because
I'm using a Western based Windows.
See attached all my attempts
Seems your test_cyrillic.rb contained a BOM which made type explode. I
needed to remove the BOM and by doing that I modified the whole
scenario of testing.
Brain Candler collected a list of all the issues with Ruby 1.9 encoding:
http://groups.google.com/group/comp.lang.ruby/msg/d032a35d6ca75b88
https://github.com/candlerb/string19/blob/master/string19.rb
I'm running out of ideas in encoding issues. I'm going to try Japanese
which seems have worked even with 1252 on my terminal and see what
happens.
2010/11/4 Boško Ivanišević <bosko.iv...@gmail.com>:
>Every time I enable chcp 65001 and do a simple 'type' I get garbled results.
>
> Results with 1.8.7 are same.
>
I needed to resave your file with Windows-1251 and set my codepage to
1251 just to be able to have 'type' work properly.
Neither Ruby, ANSICON or win32consoled worked for me. Maybe is because
I'm using a Western based Windows.
See attached all my attempts
Seems your test_cyrillic.rb contained a BOM which made type explode. I
needed to remove the BOM and by doing that I modified the whole
scenario of testing.
2010/11/4 Boško Ivanišević <bosko.iv...@gmail.com>:
>Every time I enable chcp 65001 and do a simple 'type' I get garbled results.
>
> Results with 1.8.7 are same.
>
I needed to resave your file with Windows-1251 and set my codepage to
1251 just to be able to have 'type' work properly.
Neither Ruby, ANSICON or win32consoled worked for me. Maybe is because
I'm using a Western based Windows.
Actually win32console and combined with Cucumber does more than what
ANSICON does.
It reads source files as UTF-8 and translate them to the Console codepage:
https://github.com/aslakhellesoy/cucumber/blob/master/lib/cucumber/formatter/unicode.rb
It fakes some Kernel elements to make win32console work on redirected mode:
https://github.com/aslakhellesoy/cucumber/blob/master/lib/cucumber/formatter/color_io.rb
The problem that Ruby 1.9 thinks $stdout and $stderr lack encoding,
they are US-ASCII even if your codepage is 1251, 1252 or 65001
(Unicode) one.
As I pointed before, 1.9 encoding is way, way, way more complicated
than I thought and Cucumber workaround some of these issues by reading
the desired console codepage and using Iconv to transform it.
I'm not an Encoding expert, and the few I know are expert about
encoding rant all day about Ruby 1.9 inability to deal properly with
encodings.
So I'm going to take a long stab on this during the weekend and see
why we are getting mixed and inconsistent results.
In the mean time, the ones having enough time for testing, please try
with Ruby 1.8.7 and different codepages.
Thank you.
I've changed my default codepage long ago due Cucumber specifically:
https://github.com/aslakhellesoy/cucumber/wiki/Troubleshooting
But I made the registry change so is permanent
I'm going to test again and see how it goes.
2010/11/5 Boško Ivanišević <bosko.iv...@gmail.com>:
>I've changed my default codepage long ago due Cucumber specifically:
> On Fri, Nov 5, 2010 at 12:34 AM, Luis Lavena <luisl...@gmail.com> wrote:
>>
>> 2010/11/4 Boško Ivanišević <bosko.iv...@gmail.com>:
>> >
>> >
>> > Results with 1.8.7 are same.
>> >
>>
>> Every time I enable chcp 65001 and do a simple 'type' I get garbled
>> results.
>>
>> I needed to resave your file with Windows-1251 and set my codepage to
>> 1251 just to be able to have 'type' work properly.
>>
>> Neither Ruby, ANSICON or win32consoled worked for me. Maybe is because
>> I'm using a Western based Windows.
>>
> That's very strange. I'm also using Western based Windows and haven't even
> installed Serbian language pack. Only thing I added is Serbian (Cyrillic)
> keyboard layout. When you open command prompt what is your initial code
> page? Is it 1251 or 437 as it is in my case. If it is 1251 did you do
> something special to set it up because I didn't do anything special to set
> 437 code page in command prompt. It was there immediately after installing
> Windows.
But I made the registry change so is permanent
I'm going to test again and see how it goes.
On Nov 5, 1:17 pm, Boško Ivanišević <bosko.ivanise...@gmail.com>
wrote:
> On Fri, Nov 5, 2010 at 10:00 AM, Octagon <g...@kaluga.ru> wrote:What does Ruby work fine with? The upstream Ruby compiled with VS
> ANSICON works fine when Ruby is not involved and purpose of ANSICON is to
> replace win32console. Since ANSICON and Ruby do not work well together I'm
> not sure it does not prevent making the solution to ANSI colors. What is a
> benefit of getting colors with garbled output? For example all Cucumber
> scenarios would not be readable at all.
>
does not print out international symbols to Windows 7 console. The
same happens
to the DevKit compiled Ruby. It is an upstream problem.
Strangely enough, when the code page is set to 65000, the interpreter
even
cannot run. Thus, Ruby is trying to treat console specially on a very
basic level:
<internal:enc/prelude>:3:in `require': incompatible character
encodings: UTF-7 a
nd US-ASCII (Encoding::CompatibilityError)
from <internal:enc/prelude>:3:in `block in <compiled>'
from <internal:enc/prelude>:1:in `each'
from <internal:enc/prelude>:1:in `<compiled>'
BTW, the test file is
# encoding: utf-8
puts "рролролрол"
ANSICON works well with color and international symbols when they
come
from normal programs.
ANSICON is still not ideal. I tried IronRuby 1.1.1 (the latest) and,
putting aside
slow starts and 4 times slower execution of my favorite test, it works
fine with
international characters both in ANSICON and Windows Console.
However,
there are no colors in ANSICON.
So, we have 2 upstream problems, but ANSICON still looks like the way
to go.
I do not know if it is of some use. But when I see garbage printed, I often find a BOM added to the file by Notepad… Ruby files should have no BOM.
Michel
De :
rubyin...@googlegroups.com [mailto:rubyin...@googlegroups.com] De la
part de Boško Ivaniševic
Envoyé : samedi 6 novembre 2010 12:34
À : rubyin...@googlegroups.com
Objet : Re: [RubyInstaller] Re: Proposal to deprecate win32console
--