[output] enable colors by default

pull/5516/head
Mike Fährmann 5 months ago
parent 14b38264e0
commit 20e2c0042b
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -4921,7 +4921,17 @@ output.colors
Type
``object`` (`key` -> `ANSI color`)
Default
``{"success": "1;32", "skip": "2"}``
.. code:: json
{
"success": "1;32",
"skip" : "2",
"debug" : "0;37",
"info" : "1;37",
"warning": "1;33",
"error" : "1;31"
}
Description
Controls the
`ANSI colors <https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797#colors--graphics-mode>`__
@ -4947,7 +4957,7 @@ output.ansi
Type
``bool``
Default
``false``
``true``
Description
| On Windows, enable ANSI escape sequences and colored output
| by setting the ``ENABLE_VIRTUAL_TERMINAL_PROCESSING`` flag for stdout and stderr.

@ -86,7 +86,7 @@ def main():
signal.signal(signal_num, signal.SIG_IGN)
# enable ANSI escape sequences on Windows
if util.WINDOWS and config.get(("output",), "ansi"):
if util.WINDOWS and config.get(("output",), "ansi", True):
from ctypes import windll, wintypes, byref
kernel32 = windll.kernel32
mode = wintypes.DWORD()

@ -14,6 +14,15 @@ import functools
import unicodedata
from . import config, util, formatter
COLORS_DEFAULT = {
"success": "1;32",
"skip" : "2",
"debug" : "0;37",
"info" : "1;37",
"warning": "1;33",
"error" : "1;31",
}
# --------------------------------------------------------------------
# Logging
@ -189,7 +198,9 @@ def configure_logging(loglevel):
handler = root.handlers[0]
opts = config.interpolate(("output",), "log")
colors = config.interpolate(("output",), "colors") or {}
colors = config.interpolate(("output",), "colors")
if colors is None:
colors = COLORS_DEFAULT
if colors and not opts:
opts = LOG_FORMAT
@ -326,10 +337,13 @@ def select():
mode = config.get(("output",), "mode")
if mode is None or mode == "auto":
if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
try:
if sys.stdout.isatty():
output = ColorOutput() if ANSI else TerminalOutput()
else:
output = PipeOutput()
except Exception:
output = PipeOutput()
elif isinstance(mode, dict):
output = CustomOutput(mode)
else:
@ -407,7 +421,10 @@ class ColorOutput(TerminalOutput):
def __init__(self):
TerminalOutput.__init__(self)
colors = config.get(("output",), "colors") or {}
colors = config.interpolate(("output",), "colors")
if colors is None:
colors = COLORS_DEFAULT
self.color_skip = "\033[{}m".format(
colors.get("skip", "2"))
self.color_success = "\r\033[{}m".format(

Loading…
Cancel
Save