c_xxxx functions can be used to wrap a piece of text in a
$(COLOR_X)...$(COLOR_RESET) block, thereby avoiding the easy mistake
of forgetting to place a COLOR_RESET.
The escape codes and special chars now live in their own module. The
color module is only concerned with detecting whether to use colors or
not.
Additional variables are defined with hard a coded ESC char, a tab and a
newline. This removes the need for echo or printf.
The color strings COLOR_* are redefined so that they don't have to be
processed by "echo -e". This is done by storing the already interpreted
ANSI sequence in a shell variable.
With this change, not only can color messages be printed using normal
`echo` with no switches: colors also work with the `info` and `warning`
builtins of make.
The COLOR_ECHO variable is kept because it is also being used (confusingly)
to intepret tabs an newlines. This will be fixed in another commit.
This change should change absolutely anything and colors should still work
as always.
On NixOS, there is no `/bin/echo`, instead
`which echo` will return
/home/benpicco/.nix-profile/bin/echo
so hard-coding the path will break here.
Use `/usr/bin/env` to get the path of `echo`.
This should be availiable on all systems at the same location.
If CC_NOCOLOR was not set by the user it was set according to the
terminal support of colored output.
But since CC_NOCOLOR is also used to set `-fdiagnostics-color` flags
this means changing `CFLAGS` according to terminal support of colored
output.
This is not needed for `-fdiagnostics-color` since this option is by
default `auto` if the compiler supports colored output, and `auto`
means it will only use color when standard error is a terminal.
The current code for detecting whether colors should be used by default
was not working. Normally what programs such as git or grep do is check
if they are writing to a pipe.
To see the issue by yourself:
$ BOARD=samr21-xpro make -C tests/periph_qdec > I_SHOULD_NOT_HAVE_COLORS 2>&1
This commit uses MAKE_TERMOUT, MAKE_TERMERR and if ANY of them is NOT
a terminal, colors are disabled.