tools: don't print a carriage return if we're not on a tty

Otherwise redirecting the output to a file leaves us with ugly ^M

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2022-05-04 11:20:01 +10:00 committed by José Expósito
parent 509747c01b
commit f22d193879

View file

@ -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