From 76f855d87bb3f8b5744301667ab21e5da9474621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 28 Oct 2024 14:59:54 +0100 Subject: [PATCH] [output] use ANSI colors only when stream is a TTY --- gallery_dl/output.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/gallery_dl/output.py b/gallery_dl/output.py index 38cacf1d..1649487b 100644 --- a/gallery_dl/output.py +++ b/gallery_dl/output.py @@ -33,15 +33,18 @@ except Exception: TTY_STDIN = False +COLORS_DEFAULT = {} COLORS = not os.environ.get("NO_COLOR") -COLORS_DEFAULT = { - "success": "1;32", - "skip" : "2", - "debug" : "0;37", - "info" : "1;37", - "warning": "1;33", - "error" : "1;31", -} if COLORS else {} +if COLORS: + if TTY_STDOUT: + COLORS_DEFAULT["success"] = "1;32" + COLORS_DEFAULT["skip"] = "2" + if TTY_STDERR: + COLORS_DEFAULT["debug"] = "0;37" + COLORS_DEFAULT["info"] = "1;37" + COLORS_DEFAULT["warning"] = "1;33" + COLORS_DEFAULT["error"] = "1;31" + if util.WINDOWS: ANSI = COLORS and os.environ.get("TERM") == "ANSI"