From 92246fc7bee29ccddea6896ab2a7f881471326c0 Mon Sep 17 00:00:00 2001 From: jpic Date: Sat, 24 Apr 2021 11:58:36 +0200 Subject: [PATCH] Dont try to color non-utf8 --- shlax/output.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shlax/output.py b/shlax/output.py index 910061c..955cb78 100644 --- a/shlax/output.py +++ b/shlax/output.py @@ -101,7 +101,11 @@ class Output: ) def highlight(self, line, highlight=True): - line = line.decode('utf8') if isinstance(line, bytes) else line + try: + line = line.decode('utf8') if isinstance(line, bytes) else line + except UnicodeDecodeError: + highlight = False + if not highlight or ( '\x1b[' in line or '\033[' in line