[ANN] win32console 1.3.0.beta2 Released

L

Luis Lavena

win32console version 1.3.0.beta2 has been released!

* <http://rubyforge.org/projects/winconsole>
* <http://github.com/luislavena/win32console>
* <http://rdoc.info/projects/luislavena/win32console>

Win32::Console allows controling the windows command line terminal
thru an OO-interface. This allows you to query the terminal (find
its size, characters, attributes, etc). The interface and functionality
should be identical to Perl's counterpart.

A port of Perl's Win32::Console and Win32::Console::ANSI modules.

This gem packages Gonzalo Garramuno's Win32::Console project, and includes
a compiled binary for speed. The Win32::Console project's home can be
found at:

http://rubyforge.org/projects/win32console

How to install:

Since this is a prerelease gem, you need updated version of RubyGems
(greater than 1.3.4)

gem install win32console --prerelease

This will install the latest available version from RubyGems.org

Changes:

### 1.3.0.beta2 / 2010-03-07

* Enhancements
* Redirect STDERR to be processed also for ANSI codes. Closes GH-4
* Allow ECHO to be displayed [jloveces]

--=20
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=E9ry
 
L

Luis Lavena

Hi Luis, thanks for this gem. I've been waiting something like this.
Quick q: does it implement all the features listed herehttp://www.xav.com/perl/site/lib/Win32/Console.html ?

thanks and best regards -botp

win32console gem is a wrapper around this project:

http://rubyforge.org/projects/win32console/

Which is a direct port from Perl.

That means API-wise should be pretty similar.

However, I've asked before what is the usage of win32console here:

http://blog.mmediasys.com/2009/12/17/win32console-upcoming-changes-and-feedback/

And people responded that they mainly use to mimic ANSI coloring in
the terminal, not all the Win32::Console functionality.

Also, in this release it no longer automates the codepage conversion,
which will need to be done manually. See here:

http://github.com/luislavena/win32console/blob/master/History.txt#L16-24

HTH,
 
R

Roger Pack

Win32::Console allows controling the windows command line terminal
thru an OO-interface. This allows you to query the terminal (find
its size, characters, attributes, etc). The interface and functionality
should be identical to Perl's counterpart.

I noticed it doesn't seem to do "too much" for colored specs.


16)
â†[31mActiveRecord::StatementInvalid in 'Abc should create a new instance
given valid attributes'
Could not find table 'abcs'â†[0m
E:/dev/ruby/old/spork/test_rails/spec/models/abc_spec.rb:11:in `block (2
levels) in <top (required)>'


Any guess as to who's to blame there?
Thanks.
-rp

E:\dev\ruby\old\spork\test_rails\spec>cat spec.opts
--colour
--format progress
--loadby mtime
--reverse
 
L

Luis Lavena

Win32::Console allows controling the windows command line terminal
thru an OO-interface. This allows you to query the terminal (find
its size, characters, attributes, etc). The interface and functionality
should be identical to Perl's counterpart.

I noticed it doesn't seem to do "too much" for colored specs.

16)
â†[31mActiveRecord::StatementInvalid in 'Abc should create a new instance
given valid attributes'
Could not find table 'abcs'â†[0m
E:/dev/ruby/old/spork/test_rails/spec/models/abc_spec.rb:11:in `block (2
levels) in <top (required)>'

Any guess as to who's to blame there?

Are you using autospec? If so, is not win32console, as I mentioned to
you before.

This as proven to work for standard Windows prompt without any issue,
and I use it for "rake spec" in rake-compiler:

C:\Users\Luis\Projects\oss\rake-compiler>type spec\spec.opts
--colour
--format nested
--loadby mtime
 
G

Gordon Thiesfeld

Thanks for the link.
Appears it is a bug with spec since autospec doesn't show colors but
normal "spec" does.

Thanks for your work on this.
-rp

If all of this code still works the way I remember it, this is
actually easy to fix. Last time I checked, autospec relies on
autotest, so you should be able to just require win32console in your
~/.autotest file. autospec runs the rspec framework as a subprocess.
It parses the results, then spits them out on the screen. On posix
systems, the escape codes work, because posix systems are designed to
handle them. In Windows, the escape codes just get dumped to stdout,
so you have to make sure the current process knows how to handle them.

I hope that makes sense.
 
L

Luis Lavena

If all of this code still works the way I remember it, this is
actually easy to fix. Last time I checked, autospec relies on
autotest, so you should be able to just require win32console in your
~/.autotest file.   autospec runs the rspec framework as a subprocess.
 It parses the results, then spits them out on the screen.  On posix
systems, the escape codes work, because posix systems are designed to
handle them.  In Windows, the escape codes just get dumped to stdout,
so you have to make sure the current process knows how to handle them.

I hope that makes sense.

It does, however, as I mentioned in the RSpec-dev mailing list post,
trying to recreate it just end prematurely, doesn't complete.

Ignoring for a second that ZenTest/autospec changes the first two
lines of the autotest rubygem stub, check the following example:

#ruby
ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32]

#gem list:

win32console (1.3.0.beta2, 1.3.0.beta1)
rspec (1.3.0)
ZenTest (4.2.1)

# ~/.autotest
STDOUT.puts "OUT: THIS IS ~/.autotest file"
STDERR.puts "ERR: THIS IS ~/.autotest file"
require 'win32console'
puts "$stdout.redirected? #{$stdout.redirected?}"
puts "$stderr.redirected? #{$stderr.redirected?}"

# rake-compiler/.autotest
STDOUT.puts "OUT: THIS IS rake-compiler/.autotest file"
STDERR.puts "ERR: THIS IS rake-compiler/.autotest file"
require 'win32console'
puts "$stdout.redirected? #{$stdout.redirected?}"
puts "$stderr.redirected? #{$stderr.redirected?}"

Running autospec in my folder, output this:

C:\Users\Luis\Projects\oss\rake-compiler>autospec
(Not running features. To run features in autotest, set
AUTOFEATURE=true.)
loading autotest/rspec
OUT: THIS IS ~/.autotest file
ERR: THIS IS ~/.autotest file
$stdout.redirected? false
$stderr.redirected? false
OUT: THIS IS rake-compiler/.autotest file
ERR: THIS IS rake-compiler/.autotest file
$stdout.redirected? false
$stderr.redirected? false
C:\Users\Luis\Tools\Ruby\ruby-1.8.6-p398-i386-mingw32\bin\ruby C:/
Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/rspec-1.3.0/bin/spec --
autospec C:/Users/Luis/Projects/oss/rake-compiler/spec/lib/rake/
javaextensiontask_spec.rb C:/Users/Luis/Projects/oss/rake-compiler/
spec/lib/rake/extensiontask_spec.rb -O spec/spec.opts

And from there beautiful colors (well, not beautiful, but seems it
works).

The following version also works:
ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]

But NOT 1.9.1:

C:\Users\Luis\Projects\oss\rake-compiler>autospec
loading autotest/rspec
OUT: THIS IS ~/.autotest file
ERR: THIS IS ~/.autotest file
$stdout.redirected? false
$stderr.redirected? false
OUT: THIS IS rake-compiler/.autotest file
ERR: THIS IS rake-compiler/.autotest file
$stdout.redirected? false
$stderr.redirected? false
C:\Users\Luis\Tools\Ruby\ruby-1.9.1-p378-i386-mingw32\bin\ruby C:/
Users/Luis/.gem/ruby/x86-mingw32/1.9.1/gems/rspec-1.3.0/bin/spec --
autospec C:/Users/Luis/Projects/oss/rake-compiler/spec/lib/rake/
extensiontask_spec.rb C:/Users/Luis/Projects/oss/rake-compiler/spec/
lib/rake/javaextensiontask_spec.rb -O spec/spec.opts
Rake::ExtensionTask
#new
(basic)
WARNING: You're cross-compiling a binary extension for JRuby, but are
using
another interpreter. If your Java classpath or extension dir settings
are not
correctly detected, then either check the appropriate environment
variables or
execute the Rake compilation task using the JRuby interpreter.
(e.g. `jruby -S rake compile:java`)

====

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.

Regards,
 
G

Gordon Thiesfeld

=3D=3D=3D=3D

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

=3D=3D=3D=3D

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]
=1B[31mred=1B[0m =1B[32mgreen=1B[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/Console=
/ANSI.rb#L103
 
L

Luis Lavena

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.
 
G

Gordon Thiesfeld

=3D=3D=3D=3D
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. =A0I'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
=A0# in color

ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]
red green
=A0# in color

ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]
=A0[31mred [0m =A0[32mgreen [0m

Autotest uses getc to read from stdout, and putc to write to it. =A0I
redefined Kernel#putc to cache escape codes and write them all at
once. =A0Otherwise, win32console won't work. =A0The problem in 1.9 is th= at
"?\e" doesn't return the byte value, but the string. =A0I'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.

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.
 
L

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.

Change received, merged and tested.

I've pushed a new beta release (beta3). This closes GH-3 report about
the incorrect behavior under autospec.

Can you guys install the new prerelease and let me know? That way we
can make it official 1.3.0 and I can move to the other projects with
pending releases ;-)

Thank you.
 
G

Gordon Thiesfeld

Change received, merged and tested.

I've pushed a new beta release (beta3). This closes GH-3 report about
the incorrect behavior under autospec.

Can you guys install the new prerelease and let me know? That way we
can make it official 1.3.0 and I can move to the other projects with
pending releases ;-)

Thank you.

It looks good to me. Thanks, Luis.
 
R

Roger Pack

Change received, merged and tested.

I've pushed a new beta release (beta3). This closes GH-3 report about
the incorrect behavior under autospec.

Can you guys install the new prerelease and let me know? That way we
can make it official 1.3.0 and I can move to the other projects with
pending releases ;-)


Interesting.
For some reason on my box, if I run "autospec", it runs this command:


E:\installs\ruby191p376\bin\ruby
E:/installs/ruby191p376/lib/ruby/gems/1.9.1/gems/rspec-1.3.0/bin/spec
--autospec E:/dev/ruby/old/spork/test_rails/spec/models/abc_spec.rb
E:/dev/ruby/old/spork/test_rails/spec/views/abcs/edit.html.erb_spec.rb
E:/dev/ruby/old/spork/test_rails/spec/views/abcs/index.html.erb_spec.rb
E:/dev/ruby/old/spork/test_rails/spec/views/abcs/new.html.erb_spec.rb
E:/dev/ruby/old/spork/test_rails/spec/views/abcs/show.html.erb_spec.rb
E:/dev/ruby/old/spork/test_rails/spec/controllers/abcs_controller_spec.rb
E:/dev/ruby/old/spork/test_rails/spec/helpers/abcs_helper_spec.rb
E:/dev/ruby/old/spork/test_rails/spec/routing/abcs_routing_spec.rb -O
spec/spec.opts

which outputs, for colors:

in prefork local.rb
E:/installs/ruby191p376/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning:
Gem::Dependency#version_requirements is deprecated and will be removed
on or after August 2010. Use #requirement
â†[32m.â†[0mâ†[32m.â†[0mâ†[31mFâ†[0mâ†[31mFâ†[0mâ†[31mFâ†[0mâ†[31mFâ†[0mâ†[31mFâ†[0mâ†[32m.â†[0mâ†[31mFâ†[0mâ†[31mFâ†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[31mFâ†[0mâ†[31mFâ†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[31mFâ†[0mâ†[31mFâ†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[31mFâ†[0mâ†[31mFâ†[0mâ†[31mFâ†[0mâ†[31mFâ†[0mâ†[31mFâ†[0m

(like it forgot to require win32console or something, even though
spec.opts has --color).

Any thoughts there? (spork via drb seems to do the same).
Thx.
-rp


If I run that command by itself, colors look fine.
If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top