1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[output] define and use global TTY_STD... values

This commit is contained in:
Mike Fährmann 2024-10-28 14:57:05 +01:00
parent e93b8efe7b
commit ee61256054
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 19 additions and 9 deletions

View File

@ -11,7 +11,6 @@
import os import os
import re import re
import ssl import ssl
import sys
import time import time
import netrc import netrc
import queue import queue
@ -23,7 +22,7 @@ import requests
import threading import threading
from requests.adapters import HTTPAdapter from requests.adapters import HTTPAdapter
from .message import Message from .message import Message
from .. import config, text, util, cache, exception from .. import config, output, text, util, cache, exception
urllib3 = requests.packages.urllib3 urllib3 = requests.packages.urllib3
@ -289,13 +288,8 @@ class Extractor():
def _check_input_allowed(self, prompt=""): def _check_input_allowed(self, prompt=""):
input = self.config("input") input = self.config("input")
if input is None: if input is None:
try: input = output.TTY_STDIN
input = sys.stdin.isatty()
except Exception:
input = False
if not input: if not input:
raise exception.StopExtraction( raise exception.StopExtraction(
"User input required (%s)", prompt.strip(" :")) "User input required (%s)", prompt.strip(" :"))

View File

@ -17,6 +17,22 @@ from . import config, util, formatter
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Globals # 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 = not os.environ.get("NO_COLOR")
COLORS_DEFAULT = { COLORS_DEFAULT = {
"success": "1;32", "success": "1;32",
@ -323,7 +339,7 @@ def select():
if mode is None or mode == "auto": if mode is None or mode == "auto":
try: try:
if sys.stdout.isatty(): if TTY_STDOUT:
output = ColorOutput() if ANSI else TerminalOutput() output = ColorOutput() if ANSI else TerminalOutput()
else: else:
output = PipeOutput() output = PipeOutput()