Colors in cygwin being displayed as raw ANSI codes

When running command-line Mercurial with the color extension on, the colors appear as expected in the Windows command prompt (cmd.exe). However, in cygwin the colors are appearing as the underlying ANSI codes (for example: ←[0;34;1m).

When I searched for a solution, it seemed it's more common for colors to work in cygwin but not in command prompt. Have I forgotten to install something useful in cygwin that would activate display of colors?

I experience the problem on both a Windows 7 64-bit and a Vista 32-bit machine. I've tried both bash and tcsh shells. I can see colors in both shells if I do something like ls --color.


Solution 1:

When you use the Cygwin console, the interpretation of control sequences is done by the Cygwin DLL. That DLL of course is only linked into Cygwin programs, so a non-Cygwin program like Mercurial will not be able to make use of that.

So why does it work when running in a cmd.exe console then, which doesn't understand control sequences in the first place? My guess would be that Mercurial uses the Windows console API when it thinks it runs in a console, and control sequences when it thinks it's running in a terminal. Perhaps that depends on whether TERM is set, so try what happens if you unset TERM.

Otherwise, try running it in a Cygwin terminal such as mintty or rxvt. There, the difference is that the control sequences are interpreted by those programs rather than the Cygwin DLL.

Solution 2:

In your .hgrc file set

[color]
mode = ansi

or

[color]
mode = auto