]> git.cworth.org Git - apitrace/commitdiff
retrace: Don't output color when stdout is not a tty (issue #143).
authorJosé Fonseca <jfonseca@vmware.com>
Sun, 9 Jun 2013 08:27:13 +0000 (09:27 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sun, 9 Jun 2013 08:27:51 +0000 (09:27 +0100)
To prevent tools that consume its output having to deal with ANSI
escape codes.

cli/cli_dump.cpp
retrace/retrace.cpp
retrace/retrace.hpp
retrace/retrace_main.cpp

index e30f6cc2b49574a00d58a111b38c82b59ca0982f..10dcd61d69bb07c8fe3c4c2ca0fa21cc5bc42aed 100644 (file)
@@ -158,7 +158,7 @@ command(int argc, char *argv[])
 #ifdef _WIN32
         color = COLOR_OPTION_ALWAYS;
 #else
-        color = isatty(1) ? COLOR_OPTION_ALWAYS : COLOR_OPTION_NEVER;
+        color = isatty(STDERR_FILENO) ? COLOR_OPTION_ALWAYS : COLOR_OPTION_NEVER;
         pipepager();
 #endif
     }
index ee876ca3eae2c5ebe092c374df1340b1c4a42020..bbd10b45c2cd58cb12a5cbe2892675b1c0f25ee8 100644 (file)
 #include <iostream>
 
 #include "os_time.hpp"
-#include "trace_dump.hpp"
 #include "retrace.hpp"
 
 
 namespace retrace {
 
 
+trace::DumpFlags dumpFlags = 0;
+
+
 static bool call_dumped = false;
 
 
 static void dumpCall(trace::Call &call) {
     if (verbosity >= 0 && !call_dumped) {
         std::cout << std::hex << call.thread_id << std::dec << " ";
-        std::cout << call;
+        trace::dump(call, std::cout, dumpFlags);
         std::cout.flush();
         call_dumped = true;
     }
index 14317cffbe96d7cbbe70c718127e537ea9aff5a1..f37f2494d7ca05b2acc27eb03791bdbecbcc6e5a 100644 (file)
@@ -38,6 +38,7 @@
 #include "trace_model.hpp"
 #include "trace_parser.hpp"
 #include "trace_profiler.hpp"
+#include "trace_dump.hpp"
 
 #include "scoped_allocator.hpp"
 
@@ -120,6 +121,7 @@ extern bool coreProfile;
 extern unsigned frameNo;
 extern unsigned callNo;
 
+extern trace::DumpFlags dumpFlags;
 
 std::ostream &warning(trace::Call &call);
 
index d1e00db3dd70eef7f651b85c18c9d4a452c0fe3c..bff8983b15a99becb7ac6dbe06ab58fcffcafdf5 100644 (file)
@@ -30,6 +30,9 @@
 #include <limits.h> // for CHAR_MAX
 #include <iostream>
 #include <getopt.h>
+#ifndef _WIN32
+#include <unistd.h> // for isatty()
+#endif
 
 #include "os_binary.hpp"
 #include "os_time.hpp"
@@ -751,6 +754,12 @@ int main(int argc, char **argv)
         }
     }
 
+#ifndef _WIN32
+    if (!isatty(STDOUT_FILENO)) {
+        dumpFlags |= trace::DUMP_FLAG_NO_COLOR;
+    }
+#endif
+
     retrace::setUp();
     if (retrace::profiling) {
         retrace::profiler.setup(retrace::profilingCpuTimes, retrace::profilingGpuTimes, retrace::profilingPixelsDrawn, retrace::profilingMemoryUsage);