Patchwork D12587: color: support the NO_COLOR environment variable

login
register
mail settings
Submitter phabricator
Date April 26, 2022, 10:29 a.m.
Message ID <differential-rev-PHID-DREV-4g7yx7dolojiw57oousa-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50935/
State New
Headers show

Comments

phabricator - April 26, 2022, 10:29 a.m.
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The https://no-color.org initiative is a good idea, it's easy to support. It
  even explicitly lists Mercurial as one of the programs that don't support it.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12587

AFFECTED FILES
  mercurial/color.py
  tests/test-status-color.t

CHANGE DETAILS




To: Alphare, #hg-reviewers
Cc: mercurial-patches, spectral, mercurial-devel

Patch

diff --git a/tests/test-status-color.t b/tests/test-status-color.t
--- a/tests/test-status-color.t
+++ b/tests/test-status-color.t
@@ -46,6 +46,15 @@ 
   [status.unknown|? ][status.unknown|b/in_b] (glob)
   [status.unknown|? ][status.unknown|in_root]
 
+NO_COLOR disables color no matter what
+  $ NO_COLOR= HGPLAINEXCEPT=color hg status --color=debug
+  ? a/1/in_a_1 (glob)
+  ? a/in_a (glob)
+  ? b/1/in_b_1 (glob)
+  ? b/2/in_b_2 (glob)
+  ? b/in_b (glob)
+  ? in_root
+
 hg status with template
   $ hg status -T "{label('red', path)}\n" --color=debug
   [red|a/1/in_a_1]
diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -211,7 +211,7 @@ 
 
 
 def _modesetup(ui):
-    if ui.plain(b'color'):
+    if ui.plain(b'color') or encoding.environ.get(b"NO_COLOR") is not None:
         return None
     config = ui.config(b'ui', b'color')
     if config == b'debug':