On Sun, Mar 31, 2013 at 10:01:21PM +0200, Manuel López-Ibáñez wrote:
> The following patch implements an option that allows printing the
> diagnostics markers ("error:", "warning:", "note:") in different
> colors (red, magenta, and green, respectively).

Thanks for working on that.

> I followed the implementation of GNU grep but we cannot directly use
> their code, since they only care about printing to stdout, while we
> need to create strings on the fly.
> 
> This patch only supports POSIX terminals, but grep has code for
> Windows, so I can implement that if wished.
> 
> Grep also supports configuring the colors via an environment variable,
> so I can extend the patch in that way if wished.

Yeah, IMHO we definitely want to support GCC_COLORS env var or similar, with
same syntax as e.g. GREP_COLORS, but with different names of the (two
letter?) color names.

> This patch only allows two options enable/disable colors (and defaults
> to disabled), but grep has auto/never/always, and I can easily extend
> the patch in that way.

IMO we also want that autodetection and default to auto.

I think we should do more than what your patch does, in particular I'd say
we should add some syntax to request colors in the warning*/error*/sorry*
etc. format strings (%c, %C, %o, %O seem to be taken, perhaps %rXY where
XY would be the two letter name of the color that GCC_COLORS accepts
as the lhs in the : separated list), then the diagnostics markers
could be just the format string to process to switch to that color
"%rer" for DK_ERROR, "%rwa" for DK_WARNING, "%rno" for DK_NOTE, then
have another color for the caret stuff, another that could be used
on immediately after %< or after the quote starting %qD etc. and we'd return
back to normal color right before the closing quote (%> or implicit).
Perhaps in the future without too much effort we could add some colors e.g.
to the expression printers, when printing some expression we could highligh
keywords in it, var names etc.  But for the start I'd hope highlighting
error:/warning:/note:, quoted text, caret lines and perhaps also the
introductory lines (In file included from, In macro ..., etc.), it could be
enough.

Also, please watch the GCC indentation rules in your code.

        Jakub

Reply via email to