diff options
Diffstat (limited to 'gallery_dl/output.py')
| -rw-r--r-- | gallery_dl/output.py | 39 |
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, |
