Skip to content

Commit

Permalink
python: lib: utils: Check that stdout is a tty before printing color
Browse files Browse the repository at this point in the history
If we are not printing to a terminal, do not include the color escape
codes, as that can cause other tools to think they are working with
binary rather than text files.

Signed-off-by: Nathan Chancellor <[email protected]>
  • Loading branch information
nathanchance committed Jan 31, 2024
1 parent 983621c commit d7bd6b2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
import shlex
import subprocess
import sys
import time


Expand Down Expand Up @@ -52,7 +53,7 @@ def print_header(string):


def print_color(color, string):
print(f"{color}{string}\033[0m", flush=True)
print(f"{color}{string}\033[0m" if sys.stdout.isatty() else string, flush=True)


def print_cyan(msg):
Expand Down

0 comments on commit d7bd6b2

Please sign in to comment.