diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2019-03-22 22:54:05 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2019-03-22 22:54:05 +0100 |
| commit | 68014d4f8e26ffbcf210dddbc4f54015cc477c39 (patch) | |
| tree | c8275e90fce27588244cac8097fc7731d8acbf66 | |
| parent | 2ce9d2935e4f491f375cf546d6ee9bc186f8ece4 (diff) | |
| download | allocbench-68014d4f8e26ffbcf210dddbc4f54015cc477c39.tar.gz allocbench-68014d4f8e26ffbcf210dddbc4f54015cc477c39.zip | |
colorize output only for ttys
| -rw-r--r-- | src/util.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/util.py b/src/util.py index 7265a6b..b7d4541 100644 --- a/src/util.py +++ b/src/util.py @@ -5,14 +5,20 @@ import src.globalvars def allocbench_msg(color, *objects, sep=' ', end='\n', file=sys.stdout): if src.globalvars.verbosity < 0: return + color = {"YELLOW": "\x1b[33m", "GREEN": "\x1b[32m", "RED": "\x1b[31m"}[color] - print(color, end="", file=file, flush=True) + is_atty = sys.stdout.isatty() + if is_atty: + print(color, end="", file=file, flush=True) + print(*objects, sep=sep, end=end, file=file) - print("\x1b[0m", end="", file=file, flush=True) + + if is_atty: + print("\x1b[0m", end="", file=file, flush=True) def print_debug(*objects, sep=' ', end='\n', file=sys.stdout): if src.globalvars.verbosity < 99: |
