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

implement 'output.colors' options (#2532)

This commit is contained in:
Mike Fährmann 2022-05-02 12:41:14 +02:00
parent 52b47c3cf9
commit 61887c895b
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 30 additions and 3 deletions

View File

@ -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 <https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797#colors--graphics-mode>`__
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`_

View File

@ -350,6 +350,10 @@
"mode": "auto",
"progress": true,
"shorten": true,
"colors": {
"success": "1;32",
"skip" : "2"
},
"skip": true,
"log": "[{name}][{levelname}] {message}",
"logfile": null,

View File

@ -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):