]> git.cworth.org Git - apitrace/commitdiff
diff: Don't use colorized line-format options when not on a tty
authorCarl Worth <cworth@cworth.org>
Mon, 13 Aug 2012 20:24:03 +0000 (13:24 -0700)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 8 Oct 2012 17:53:59 +0000 (18:53 +0100)
The color output is convenient when manually looking at the
output. But when saving output to a file, (for example, for use in the
test suite), it's useful to have a much more minimal output.

scripts/tracediff.py

index 86d1e0020f1e55a72c196b93c8ba9a20c727e7a9..26395879a10b8c54f3308f6a3a8eeab2e5506414 100755 (executable)
@@ -70,6 +70,8 @@ else:
 
 def diff(ref_trace, src_trace):
 
+    isatty = sys.stdout.isatty()
+
     ref_dumper = Dumper(ref_trace, options.ref_calls)
     src_dumper = Dumper(src_trace, options.src_calls)
 
@@ -78,6 +80,9 @@ def diff(ref_trace, src_trace):
         diff_args = [
                 'diff',
                 '--speed-large-files',
+            ]
+        if isatty:
+            diff_args += [
                 '--old-line-format=' + start_delete + '%l' + end_delete + '\n',
                 '--new-line-format=' + start_insert + '%l' + end_insert + '\n',
             ]
@@ -92,6 +97,9 @@ def diff(ref_trace, src_trace):
                 'wdiff',
                 #'--terminal',
                 '--avoid-wraps',
+            ]
+        if isatty:
+            diff_args += [
                 '--start-delete=' + start_delete,
                 '--end-delete=' + end_delete,
                 '--start-insert=' + start_insert,
@@ -105,7 +113,7 @@ def diff(ref_trace, src_trace):
     src_dumper.dump.wait()
 
     less = None
-    if sys.stdout.isatty():
+    if isatty:
         less = subprocess.Popen(
             args = ['less', '-FRXn'],
             stdin = subprocess.PIPE