From f9929052a04832b3e5bf6c0daf21719a27057c16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sun, 9 Jun 2013 09:27:13 +0100 Subject: [PATCH] retrace: Don't output color when stdout is not a tty (issue #143). To prevent tools that consume its output having to deal with ANSI escape codes. --- cli/cli_dump.cpp | 2 +- retrace/retrace.cpp | 6 ++++-- retrace/retrace.hpp | 2 ++ retrace/retrace_main.cpp | 9 +++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cli/cli_dump.cpp b/cli/cli_dump.cpp index e30f6cc..10dcd61 100644 --- a/cli/cli_dump.cpp +++ b/cli/cli_dump.cpp @@ -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 } diff --git a/retrace/retrace.cpp b/retrace/retrace.cpp index ee876ca..bbd10b4 100644 --- a/retrace/retrace.cpp +++ b/retrace/retrace.cpp @@ -28,20 +28,22 @@ #include #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; } diff --git a/retrace/retrace.hpp b/retrace/retrace.hpp index 14317cf..f37f249 100644 --- a/retrace/retrace.hpp +++ b/retrace/retrace.hpp @@ -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); diff --git a/retrace/retrace_main.cpp b/retrace/retrace_main.cpp index d1e00db..bff8983 100644 --- a/retrace/retrace_main.cpp +++ b/retrace/retrace_main.cpp @@ -30,6 +30,9 @@ #include // for CHAR_MAX #include #include +#ifndef _WIN32 +#include // 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); -- 2.45.2