ruby-on-railsrubygit-bashansi-colors

How to get color in Windows gitbash using bundle exec rake test


I am following Rails Tutorial. I am on section 3.7.1 and I am trying to get color in my gitbash command prompt when running bundle exec rake test. I have tried installing ansi, the win32console gem and the gem called turn and nothing seems to work.

Is it even possible to get red and green colors when running bundle exec rake test?


Solution

  • You definitely can get colored output to show up. But not with using the standard Windows cmd.exe or powershell. Gems won't help. You need to need add the ability to correctly interpret ANSI escape codes to your system -- something that cmd and powershell aren't able to do. (ANSI.sys was how ANSI escape codes were handled under DOS. cmd and powershell don't use it.)

    You need to (1) install ANSICON and/or (2) install and use a different console/console emulator or shell that handles colors (ANSI escape codes).

    (1) ANSICON is a program for Windows that interprets ANSI escape codes so that color is displayed. It kind of runs 'on top of' cmd or powershell. You can set it up so that it's always used whenever you use cmd or powershell, or use it only at specific times. Most people install this and are really happy with it. Jason Karns wrote a blog post about installing and using ANSICON for git bash (on Windows) that folks have found helpful.

    (2) Here are the popular options for alternatives to cmd/powershell. These are console emulators and tools and shell alternatives:

    Some searching might turn up additional options. These are the options most talked about and used (based on talking with others IRL, StackOverflow, and doing searching now and previously.)

    Install and set one of those options (it won't take long), and then you'll be all set to see the helpful colors used by RSpec or git or whatever.