From ee61256054ad5d7dc0175b38d3716457f1c329b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 28 Oct 2024 14:57:05 +0100 Subject: [PATCH] [output] define and use global TTY_STD... values --- gallery_dl/extractor/common.py | 10 ++-------- gallery_dl/output.py | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 2146fa65..1c1dbe49 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -11,7 +11,6 @@ import os import re import ssl -import sys import time import netrc import queue @@ -23,7 +22,7 @@ import requests import threading from requests.adapters import HTTPAdapter from .message import Message -from .. import config, text, util, cache, exception +from .. import config, output, text, util, cache, exception urllib3 = requests.packages.urllib3 @@ -289,13 +288,8 @@ class Extractor(): def _check_input_allowed(self, prompt=""): input = self.config("input") - if input is None: - try: - input = sys.stdin.isatty() - except Exception: - input = False - + input = output.TTY_STDIN if not input: raise exception.StopExtraction( "User input required (%s)", prompt.strip(" :")) diff --git a/gallery_dl/output.py b/gallery_dl/output.py index 646795c3..38cacf1d 100644 --- a/gallery_dl/output.py +++ b/gallery_dl/output.py @@ -17,6 +17,22 @@ 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 = not os.environ.get("NO_COLOR") COLORS_DEFAULT = { "success": "1;32", @@ -323,7 +339,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()