Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2022-03-16 18:38:57 +0300
committerGitHub <noreply@github.com>2022-03-16 18:38:57 +0300
commit4e9c1017edc3253f8cd95c9d5fef7bbac4b18211 (patch)
tree25932533ea66f176f1390725c95b7bffb4028c78
parentb12b39db05d605cfb946f84afd27e0f6cf3c9e13 (diff)
parentb172dc1c90213956d8a55a0cbd98b74d292a69fe (diff)
Merge pull request #10260 from hugovk/colour-env-vars
Enable FORCE_COLOR and NO_COLOR for terminal colouring
-rw-r--r--AUTHORS1
-rw-r--r--CHANGES1
-rw-r--r--doc/man/sphinx-build.rst16
-rw-r--r--sphinx/util/console.py4
4 files changed, 22 insertions, 0 deletions
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 a7c913c9c..ab3b86d3a 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
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 <https://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
diff --git a/sphinx/util/console.py b/sphinx/util/console.py
index cc22390a5..abdbf4219 100644
--- a/sphinx/util/console.py
+++ b/sphinx/util/console.py
@@ -49,9 +49,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():