summaryrefslogtreecommitdiffstats
path: root/gallery_dl/output.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2024-12-02 00:31:59 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2024-12-02 00:31:59 -0500
commit1981ccaaea6eab2cf32536ec5afe132a870914d8 (patch)
tree013f1e17d922d3a6abf7f57aa6a175c2ce5d93bc /gallery_dl/output.py
parentfc004701f923bb954a22c7fec2ae8d607e78cb2b (diff)
New upstream version 1.28.0.upstream/1.28.0
Diffstat (limited to 'gallery_dl/output.py')
-rw-r--r--gallery_dl/output.py39
1 files changed, 30 insertions, 9 deletions
diff --git a/gallery_dl/output.py b/gallery_dl/output.py
index 13b6a8a..1649487 100644
--- a/gallery_dl/output.py
+++ b/gallery_dl/output.py
@@ -17,15 +17,34 @@ from . import config, util, formatter
# --------------------------------------------------------------------
# Globals
+try:
+ TTY_STDOUT = sys.stdout.isatty()
+except Exception:
+ TTY_STDOUT = False
+
+try:
+ TTY_STDERR = sys.stderr.isatty()
+except Exception:
+ TTY_STDERR = False
+
+try:
+ TTY_STDIN = sys.stdin.isatty()
+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"
@@ -323,7 +342,7 @@ def select():
if mode is None or mode == "auto":
try:
- if sys.stdout.isatty():
+ if TTY_STDOUT:
output = ColorOutput() if ANSI else TerminalOutput()
else:
output = PipeOutput()
@@ -331,6 +350,8 @@ def select():
output = PipeOutput()
elif isinstance(mode, dict):
output = CustomOutput(mode)
+ elif not mode:
+ output = NullOutput()
else:
output = {
"default" : PipeOutput,