views:

342

answers:

5

I have installed Ramaze (on Windows XP) and it suggested I also install win32console to get coloured log output when it is running.

However, after doing so I get escape codes rather than colours as shown below:

W [2009-04-29 09:02:55 $5064]  WARN | : ←[33mNo explicit root folder found, assuming it is C:/Projects/Ruby/Ramaze/Conferences←[0m
D [2009-04-29 09:02:55 $5064] DEBUG | : ←[34mUsing webrick←[0m
I [2009-04-29 09:02:55 $5064]  INFO | : ←[37mWEBrick 1.3.1←[0m
I [2009-04-29 09:02:55 $5064]  INFO | : ←[37mruby 1.8.6 (2008-08-11) [i386-mswin32]←[0m
D [2009-04-29 09:02:55 $5064] DEBUG | : ←[34mTCPServer.new(0.0.0.0, 7000)←[0m
D [2009-04-29 09:02:55 $5064] DEBUG | : ←[34mRack::Handler::WEBrick is mounted on /.←[0m
I [2009-04-29 09:02:55 $5064]  INFO | : ←[37mWEBrick::HTTPServer#start: pid=5064 port=7000←[0m

This happens even on a clean install of Ruby/Ramaze/win32console

My setup is:

  • Windows XP with SP#3
  • ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
  • rubygems version 1.3.1
  • win32console gem version 1.2.0

Incidentally, the following test program seems to work so I am wondering if it is a Ramaze/win32console issue on my machine.

#!/usr/bin/ruby
require 'rubygems'
require 'win32console'

[0, 1, 4, 5, 7].each do |attr|
  puts '----------------------------------------------------------------'
  puts "ESC[#{attr};Foreground;Background"
  30.upto(37) do |fg|
    40.upto(47) do |bg|
      print "\033[#{attr};#{fg};#{bg}m #{fg};#{bg}  "
    end
  puts "\033[0m"
  end
end
A: 

Maybe it's not an answer you are looking for, but I use MSYS/MinGW on Windows and it's bash displays colors properly without win32console gem.

klew
Thanks - I guess that is one option and I might try that later. I'd like to find out the root cause first though (especially given that others seem to have it working). Thanks for the suggestion anyway!
A: 

I think this is caused by the difference in the formatting string between your code and the code in Ramaze (or Innate).

"\e[#{COLOR_CODE[LEVEL_COLOR[severity]]}m#{string}\e[0m"

That expands to (for red, and "Hello" being the String):

"\e[31mHello\e[0m"

\e, in Ruby, is converted to \033, so that shouldn't give us trouble:

of course, is equivalent being equivalent with \033

"\033" == "\e" # => true

The major difference is that Ramaze doesn't specify a background-color, as that may result in ugly output if it contrasts too much with the default background of the terminal. But as it may just as well be completely unreadable if your background is blue, red, white, or any of the other foreground colors that Ramaze uses for logging, I think we should define the background explicitly, and hope that this will also fix your windows issue.

manveru
I'm actually get escape codes like ←[34m rather than any colours at all so it's not (yet) a problem with contrast or ugly colour schemes.
A: 

try adding this in your app.rb

require "win32console"
require "Win32/Console/ANSI"
alex
I tried this in my app and also in Ramaze's app.rb (in case that's what you meant) but no improvement - still escape sequences.
+1  A: 

Try

require 'rubygems'
require 'win32console'
include Win32::Console::ANSI
include Term::ANSIColor
kirushik
A: 

win32console needs to be required before Ramaze start.

This is because Ramaze and its logging mechanism are keeping references to stdout and stderr prior win32console replace them.

Luis Lavena
I have "require 'win32console'" before the line requiring ramaze but that doesn't seem to help. Or is that not quite what you meant?
You should install win32console gem and require it before ramaze. That should wrap ANSI coloring and properly display colors on Windows prompt.
Luis Lavena