Skip to content

Commit

Permalink
implement 'output.colors' options (#2532)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed May 2, 2022
1 parent 52b47c3 commit 61887c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
14 changes: 14 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`_
Expand Down
4 changes: 4 additions & 0 deletions docs/gallery-dl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@
"mode": "auto",
"progress": true,
"shorten": true,
"colors": {
"success": "1;32",
"skip" : "2"
},
"skip": true,
"log": "[{name}][{levelname}] {message}",
"logfile": null,
Expand Down
15 changes: 12 additions & 3 deletions gallery_dl/output.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -310,16 +310,25 @@ def progress(self, bytes_total, bytes_downloaded, bytes_per_second):

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):
Expand Down

0 comments on commit 61887c8

Please sign in to comment.