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;
|
disableWarnings = false;
|
||||||
warningsAsErrors = false;
|
warningsAsErrors = false;
|
||||||
quiet = false;
|
quiet = false;
|
||||||
|
forceColoredOutput = false;
|
||||||
disableLineWrap = false;
|
disableLineWrap = false;
|
||||||
emitPerfWarnings = true;
|
emitPerfWarnings = true;
|
||||||
emitInstrumentation = false;
|
emitInstrumentation = false;
|
||||||
|
|||||||
4
ispc.h
4
ispc.h
@@ -407,6 +407,10 @@ struct Globals {
|
|||||||
/** Indicates whether all printed output should be surpressed. */
|
/** Indicates whether all printed output should be surpressed. */
|
||||||
bool quiet;
|
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
|
/** Indicates whether calls should be emitted in the program to an
|
||||||
externally-defined program instrumentation function. (See the
|
externally-defined program instrumentation function. (See the
|
||||||
"Instrumenting your ispc programs" section in the user's
|
"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",
|
printf(" [--arch={%s}]\t\tSelect target architecture\n",
|
||||||
Target::SupportedTargetArchs());
|
Target::SupportedTargetArchs());
|
||||||
printf(" [--c++-include-file=<name>]\t\tSpecify name of file to emit in #include statement in generated C++ code.\n");
|
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=<cpu>]\t\t\tSelect target CPU type\n");
|
||||||
printf(" <cpu>={%s}\n", Target::SupportedTargetCPUs().c_str());
|
printf(" <cpu>={%s}\n", Target::SupportedTargetCPUs().c_str());
|
||||||
printf(" [-D<foo>]\t\t\t\t#define given value when running preprocessor\n");
|
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
|
#ifndef ISPC_IS_WINDOWS
|
||||||
else if (!strcmp(argv[i], "--pic"))
|
else if (!strcmp(argv[i], "--pic"))
|
||||||
generatePIC = true;
|
generatePIC = true;
|
||||||
|
else if (!strcmp(argv[i], "--colored-output"))
|
||||||
|
g->forceColoredOutput = true;
|
||||||
#endif // !ISPC_IS_WINDOWS
|
#endif // !ISPC_IS_WINDOWS
|
||||||
else if (!strcmp(argv[i], "--quiet"))
|
else if (!strcmp(argv[i], "--quiet"))
|
||||||
g->quiet = true;
|
g->quiet = true;
|
||||||
|
|||||||
5
util.cpp
5
util.cpp
@@ -44,6 +44,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <alloca.h>
|
#include <alloca.h>
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@@ -94,6 +95,10 @@ static bool
|
|||||||
lHaveANSIColors() {
|
lHaveANSIColors() {
|
||||||
static bool r = (getenv("TERM") != NULL &&
|
static bool r = (getenv("TERM") != NULL &&
|
||||||
strcmp(getenv("TERM"), "dumb") != 0);
|
strcmp(getenv("TERM"), "dumb") != 0);
|
||||||
|
#ifndef ISPC_IS_WINDOWS
|
||||||
|
r &= isatty(2);
|
||||||
|
#endif // !ISPC_IS_WINDOWS
|
||||||
|
r |= g->forceColoredOutput;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user