3

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
Martin Smith
  • 213
  • 3
  • 10
  • Ramaze seems to use Analogger for logging in some cases. I'm not sure if this is what is used to log to the console. It looks like Ramaze passes it a :colorize trait to tell it whether or not to colour log output. I didn't have this installed (I do now) so this may be a red (!) herring. – Martin Smith Apr 30 '09 at 10:36

6 Answers6

1

Try

require 'rubygems'
require 'win32console'
include Win32::Console::ANSI
include Term::ANSIColor
kirushik
  • 1,296
  • 1
  • 10
  • 20
1

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
  • 14,837
  • 7
  • 47
  • 59
  • 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! – Martin Smith Apr 29 '09 at 13:45
0

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
  • 10,348
  • 1
  • 37
  • 39
  • I have "require 'win32console'" before the line requiring ramaze but that doesn't seem to help. Or is that not quite what you meant? – Martin Smith Nov 13 '09 at 11:43
  • You should install win32console gem and require it before ramaze. That should wrap ANSI coloring and properly display colors on Windows prompt. – Luis Lavena Nov 14 '09 at 17:27
0

I just tried the suggestion in How to load ANSI escape codes or get coloured file listing in WinXP cmd shell and this worked nicely.

Basically, I grabbed ANSICon and then ran:

ansicon.exe -I (that's a capital 'i' there)

from the x86 sub-folder it was extracted to. This installed the ANSI colour code DLL as hook to all cmd.exe windows opened after that. Yo and behold - colours in cmd.exe

Community
  • 1
  • 1
Martin Smith
  • 213
  • 3
  • 10
0

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
  • 2,770
  • 1
  • 20
  • 17
  • 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. – Martin Smith Apr 30 '09 at 10:31
0

try adding this in your app.rb

require "win32console"
require "Win32/Console/ANSI"
alex
  • 2,036
  • 2
  • 16
  • 19
  • 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. – Martin Smith Apr 30 '09 at 10:32