Skip to content

Commit

Permalink
implement 'output.ansi' option (#2628)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed May 29, 2022
1 parent 415c208 commit 603af48
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2948,6 +2948,17 @@ Description
.. __: `output.mode`_


output.ansi
-----------
Type
``bool``
Default
``false``
Description
| On Windows, enable ANSI escape sequences and colored output
| by setting the ``ENABLE_VIRTUAL_TERMINAL_PROCESSING`` flag for stdout and stderr.

output.skip
-----------
Type
Expand Down
3 changes: 3 additions & 0 deletions docs/gallery-dl-example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@
"#": "while also considering wider East-Asian characters",
"shorten": "eaw",

"#": "enable ANSI escape sequences on Windows",
"ansi": true,

"#": "write logging messages to a separate file",
"logfile": {
"path": "~/gallery-dl/log.txt",
Expand Down
1 change: 1 addition & 0 deletions docs/gallery-dl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@
"mode": "auto",
"progress": true,
"shorten": true,
"ansi": false,
"colors": {
"success": "1;32",
"skip" : "2"
Expand Down
15 changes: 15 additions & 0 deletions gallery_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ def main():
else:
signal.signal(signal_num, signal.SIG_IGN)

# enable ANSI escape sequences on Windows
if util.WINDOWS and config.get(("output",), "ansi"):
from ctypes import windll, wintypes, byref
kernel32 = windll.kernel32
mode = wintypes.DWORD()

for handle_id in (-11, -12): # stdout and stderr
handle = kernel32.GetStdHandle(handle_id)
kernel32.GetConsoleMode(handle, byref(mode))
if not mode.value & 0x4:
mode.value |= 0x4
kernel32.SetConsoleMode(handle, mode)

output.ANSI = True

# extractor modules
modules = config.get(("extractor",), "modules")
if modules is not None:
Expand Down

0 comments on commit 603af48

Please sign in to comment.