From 61887c895b3e406eeeddfd858f7c8e6904fc92af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 2 May 2022 12:41:14 +0200 Subject: [PATCH] implement 'output.colors' options (#2532) --- docs/configuration.rst | 14 ++++++++++++++ docs/gallery-dl.conf | 4 ++++ gallery_dl/output.py | 15 ++++++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index bbbb3eb8..b2245762 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -2877,6 +2877,19 @@ Description with a display width greater than 1. +output.colors +------------- +Type + ``object`` +Default + ``{"success": "1;32", "skip": "2"}`` +Description + Controls the `ANSI colors `__ + used with |mode: color|__ for successfully downloaded or skipped files. + +.. __: `output.mode`_ + + output.skip ----------- Type @@ -3824,6 +3837,7 @@ Description .. |Postprocessor Configuration| replace:: ``Postprocessor Configuration`` .. |strptime| replace:: strftime() and strptime() Behavior .. |postprocessors| replace:: ``postprocessors`` +.. |mode: color| replace:: ``"mode": "color"`` .. _base-directory: `extractor.*.base-directory`_ .. _date-format: `extractor.*.date-format`_ diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index d395bea3..acb02626 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -350,6 +350,10 @@ "mode": "auto", "progress": true, "shorten": true, + "colors": { + "success": "1;32", + "skip" : "2" + }, "skip": true, "log": "[{name}][{levelname}] {message}", "logfile": null, diff --git a/gallery_dl/output.py b/gallery_dl/output.py index 7e00e1aa..8ec9976b 100644 --- a/gallery_dl/output.py +++ b/gallery_dl/output.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2015-2021 Mike Fährmann +# Copyright 2015-2022 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -310,16 +310,25 @@ class TerminalOutput(NullOutput): class ColorOutput(TerminalOutput): + def __init__(self): + TerminalOutput.__init__(self) + + colors = config.get(("output",), "colors") or {} + self.color_skip = "\033[{}m".format( + colors.get("skip", "2")) + self.color_success = "\r\033[{}m".format( + colors.get("success", "1;32")) + def start(self, path): stdout = sys.stdout stdout.write(self.shorten(path)) stdout.flush() def skip(self, path): - sys.stdout.write("\033[2m" + self.shorten(path) + "\033[0m\n") + sys.stdout.write(self.color_skip + self.shorten(path) + "\033[0m\n") def success(self, path, tries): - sys.stdout.write("\r\033[1;32m" + self.shorten(path) + "\033[0m\n") + sys.stdout.write(self.color_success + self.shorten(path) + "\033[0m\n") class EAWCache(dict):