Tag Archives: Windows

Disable the ←’s in Rails on Windows

If you run the demo Rails server on Windows you’ll soon see something like this in the console:

Started GET "/rails/info/properties" for at 2011-03-05 19:45:31 +0200
Processing by Rails::InfoController#properties as HTML
←[1m←[36mSQL (0.0ms)←[0m ←[1m SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
Rendered inline template (0.0ms)
Completed 200 OK in 80ms (Views: 1.0ms | ActiveRecord: 0.0ms)

The weird sequences with the arrows are ANSI escape codes which are supposed to make the output colorful (the arrows represent the ASCII “escape” character). Unfortunately, cmd.exe (the Windows console) doesn’t support these sequences and displays them in their raw ugliness.

On Rails 3, you can tell Rails not to use these sequences by setting the colorize_logging variable to false. Add these lines to the Application class in application.rb:

    # Windows cmd.exe doesn't support ANSI colors, so disable them
    config.colorize_logging = false

If you’re wondering how some Windows programs such as PowerShell have color output in the console, the answer is that they probably use the Windows API function SetConsoleTextAttribute for this.


An alternative solution is to to use win32console. This is a ruby module which overrides ruby’s output methods so they emulate ANSI color support. To use it, add this line to your application’s Gemfile (located at the application root directory):

    gem 'win32console', :platforms => :mingw