Don't generate colorized output escapes when stderr isn't a TTY.

When piping to a pile, more/less, etc, this is generally undesirable.

This behavior can be overridden with the --colorized-output command-line
flag.
This commit is contained in:
Matt Pharr
2012-06-04 09:20:57 -07:00
parent 6118643232
commit 1397dbdabc
4 changed files with 15 additions and 0 deletions

View File

@@ -44,6 +44,7 @@
#endif
#else
#include <alloca.h>
#include <unistd.h>
#endif
#include <stdio.h>
@@ -94,6 +95,10 @@ static bool
lHaveANSIColors() {
static bool r = (getenv("TERM") != NULL &&
strcmp(getenv("TERM"), "dumb") != 0);
#ifndef ISPC_IS_WINDOWS
r &= isatty(2);
#endif // !ISPC_IS_WINDOWS
r |= g->forceColoredOutput;
return r;
}