From 2a700cf8e551ac44aebe938640b673f99af1cf9f Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 12 Mar 2022 14:30:35 +0200 Subject: [PATCH 1/3] Enable FORCE_COLOR and NO_COLOR for terminal colouring --- sphinx/util/console.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sphinx/util/console.py b/sphinx/util/console.py index 48b566283..f851ea9bb 100644 --- a/sphinx/util/console.py +++ b/sphinx/util/console.py @@ -57,9 +57,13 @@ def term_width_line(text: str) -> str: def color_terminal() -> bool: + if 'NO_COLOR' in os.environ: + return False if sys.platform == 'win32' and colorama is not None: colorama.init() return True + if 'FORCE_COLOR' in os.environ: + return True if not hasattr(sys.stdout, 'isatty'): return False if not sys.stdout.isatty(): From cdf9456699fabae836a94ed22956d00b12f47a21 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 13 Mar 2022 17:43:22 +0200 Subject: [PATCH 2/3] Document NO_COLOR and FORCE_COLOR environment variables --- doc/man/sphinx-build.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/man/sphinx-build.rst b/doc/man/sphinx-build.rst index ca16b265a..9bba4a55a 100644 --- a/doc/man/sphinx-build.rst +++ b/doc/man/sphinx-build.rst @@ -304,6 +304,22 @@ variables to customize behavior: Additional options for :program:`sphinx-build`. These options can also be set via the shortcut variable **O** (capital 'o'). +.. describe:: NO_COLOR + + When set (regardless of value), :program:`sphinx-build` will not use color + in terminal output. ``NO_COLOR`` takes precedence over ``FORCE_COLOR``. See + `no-color.org `__ for other libraries supporting this + community standard. + + .. versionadded:: 4.5.0 + +.. describe:: FORCE_COLOR + + When set (regardless of value), :program:`sphinx-build` will use color in + terminal output. ``NO_COLOR`` takes precedence over ``FORCE_COLOR``. + + .. versionadded:: 4.5.0 + .. _when-deprecation-warnings-are-displayed: Deprecation Warnings From b172dc1c90213956d8a55a0cbd98b74d292a69fe Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 13 Mar 2022 17:48:04 +0200 Subject: [PATCH 3/3] Update AUTHORS and CHANGES --- AUTHORS | 1 + CHANGES | 1 + 2 files changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index 4b6aa8ffb..492817cfb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -73,6 +73,7 @@ Other contributors, listed alphabetically, are: * Pauli Virtanen -- autodoc improvements, autosummary extension * Eric N. Vander Weele -- autodoc improvements * Stefan van der Walt -- autosummary extension +* Hugo van Kemenade -- support FORCE_COLOR and NO_COLOR * Thomas Waldmann -- apidoc module fixes * John Waltman -- Texinfo builder * Barry Warsaw -- setup command improvements diff --git a/CHANGES b/CHANGES index 24e519b7d..3790f48ff 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,7 @@ Deprecated Features added -------------- +* #10260: Enable ``FORCE_COLOR`` and ``NO_COLOR`` for terminal colouring * #10234: autosummary: Add "autosummary" CSS class to summary tables * #10125: extlinks: Improve suggestion message for a reference having title * #9494, #9456: html search: Add a config variable