tools: don't print a carriage return if we're not on a tty
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 4 May 2022 01:20:01 +0000 (11:20 +1000)
committerJosé Expósito <jose.exposito89@gmail.com>
Wed, 4 May 2022 17:32:27 +0000 (17:32 +0000)
Otherwise redirecting the output to a file leaves us with ugly ^M

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
tools/libinput-analyze-recording.py

index 892bb45..c95e393 100755 (executable)
@@ -30,6 +30,7 @@
 # Input is a libinput record yaml file
 
 import argparse
+import os
 import sys
 import yaml
 import libevdev
@@ -95,6 +96,8 @@ def main(argv):
     ignored_axes = [libevdev.evbit(axis) for axis in args.ignore.split(",") if axis]
     only_axes = [libevdev.evbit(axis) for axis in args.only.split(",") if axis]
 
+    cr = "\r" if os.isatty(sys.stdout.fileno()) else ""
+
     yml = yaml.safe_load(open(args.path[0]))
     if yml["ndevices"] > 1:
         print(f"WARNING: Using only first {yml['ndevices']} devices in recording")
@@ -182,7 +185,7 @@ def main(argv):
                 print(" | ".join(fields))
             else:
                 continuation_count += 1
-                print(f"\r ... +{continuation_count}", end="", flush=True)
+                print(f"{cr} ... +{continuation_count}", end="", flush=True)
 
     # Print out any rel/abs axes that not generate events in
     # this recording