diff --git a/ispc.cpp b/ispc.cpp index 341206c6..38b9ec70 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -578,6 +578,7 @@ Globals::Globals() { disableWarnings = false; warningsAsErrors = false; quiet = false; + forceColoredOutput = false; disableLineWrap = false; emitPerfWarnings = true; emitInstrumentation = false; diff --git a/ispc.h b/ispc.h index 4cbbce7d..26e592ff 100644 --- a/ispc.h +++ b/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 diff --git a/main.cpp b/main.cpp index 417c1c3c..c80429c2 100644 --- a/main.cpp +++ b/main.cpp @@ -83,6 +83,9 @@ usage(int ret) { printf(" [--arch={%s}]\t\tSelect target architecture\n", Target::SupportedTargetArchs()); printf(" [--c++-include-file=]\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=]\t\t\tSelect target CPU type\n"); printf(" ={%s}\n", Target::SupportedTargetCPUs().c_str()); printf(" [-D]\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; diff --git a/util.cpp b/util.cpp index a5cf5a92..73debb77 100644 --- a/util.cpp +++ b/util.cpp @@ -44,6 +44,7 @@ #endif #else #include +#include #endif #include @@ -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; }