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:
1
ispc.cpp
1
ispc.cpp
@@ -578,6 +578,7 @@ Globals::Globals() {
|
||||
disableWarnings = false;
|
||||
warningsAsErrors = false;
|
||||
quiet = false;
|
||||
forceColoredOutput = false;
|
||||
disableLineWrap = false;
|
||||
emitPerfWarnings = true;
|
||||
emitInstrumentation = false;
|
||||
|
||||
4
ispc.h
4
ispc.h
@@ -407,6 +407,10 @@ struct Globals {
|
||||
/** Indicates whether all printed output should be surpressed. */
|
||||
bool quiet;
|
||||
|
||||
/** Always use ANSI escape sequences to colorize warning and error
|
||||
messages, even if piping output to a file, etc. */
|
||||
bool forceColoredOutput;
|
||||
|
||||
/** Indicates whether calls should be emitted in the program to an
|
||||
externally-defined program instrumentation function. (See the
|
||||
"Instrumenting your ispc programs" section in the user's
|
||||
|
||||
5
main.cpp
5
main.cpp
@@ -83,6 +83,9 @@ usage(int ret) {
|
||||
printf(" [--arch={%s}]\t\tSelect target architecture\n",
|
||||
Target::SupportedTargetArchs());
|
||||
printf(" [--c++-include-file=<name>]\t\tSpecify name of file to emit in #include statement in generated C++ code.\n");
|
||||
#ifndef ISPC_IS_WINDOWS
|
||||
printf(" [--colored-output]\t\tAlways use terminal colors in error/warning messages.\n");
|
||||
#endif
|
||||
printf(" [--cpu=<cpu>]\t\t\tSelect target CPU type\n");
|
||||
printf(" <cpu>={%s}\n", Target::SupportedTargetCPUs().c_str());
|
||||
printf(" [-D<foo>]\t\t\t\t#define given value when running preprocessor\n");
|
||||
@@ -401,6 +404,8 @@ int main(int Argc, char *Argv[]) {
|
||||
#ifndef ISPC_IS_WINDOWS
|
||||
else if (!strcmp(argv[i], "--pic"))
|
||||
generatePIC = true;
|
||||
else if (!strcmp(argv[i], "--colored-output"))
|
||||
g->forceColoredOutput = true;
|
||||
#endif // !ISPC_IS_WINDOWS
|
||||
else if (!strcmp(argv[i], "--quiet"))
|
||||
g->quiet = true;
|
||||
|
||||
5
util.cpp
5
util.cpp
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user