msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.3k stars 1.23k forks source link

GCC 7.1 diagnostics color support outside of mintty #2683

Open melak47 opened 7 years ago

melak47 commented 7 years ago

The color support currently implemented (in this patch) doesn't always work outside of bash/mintty/winpty etcetera.

In gcc/diagnostic-color.c with the above patch:

You can of course set TERM to some bogus value like "cmd", but your remote shells may not appreciate that - and "xterm" or even "ansi" can lead to somewhat garbled output on your end of a SSH connection. Maybe "cygwin" could work, but I'd prefer not to have to work around this in the first place.

Ede123 commented 7 years ago

I was trying to achieve color output with gcc using ninja / ccache and wasn't successful either. Maybe related?

melak47 commented 7 years ago

@Ede123 The linked patch specifically detects mintty named pipes, and wouldn't recognize ninja's named pipes ( "\\.\pipe\ninja_pid<PID>_sp<IOPORT>") as a "terminal" to enable color support for, so you'd have to use -fdiagnostics-color(=always). Even then, ninja will strip such escape codes unconditionally under certain conditions (see StripAnsiEscapeCodes used in build.cc). So it should work when the output goes to a real console window (regular conhost, ConEmu, winpty). If ninja's output is going to a pipe, or you use verbose output, the escape codes will be stripped, though.

Ede123 commented 7 years ago

I tried -fdiagnostics-color, but couldn't make it work with that option alone. I must admit it also wasn't important enough for me to investigate further, since there were three programs involved (ninja, ccache and g++) each of which could have stripped the coloring...

lhmouse commented 7 years ago

Try this ? :joy:

This not only works on Windows 10 but also on Windows 7. Theoretically it should work on Windows 2000 and XP too but I haven't tested yet.