Patchwork D1532: color: respect HGPLAINEXCEPT=color to allow colors in otherwise-plain settings

login
register
mail settings
Submitter phabricator
Date Nov. 28, 2017, 6:28 p.m.
Message ID <differential-rev-PHID-DREV-hyaa32sivpr4xevd7tkg-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/25781/
State Superseded
Headers show

Comments

phabricator - Nov. 28, 2017, 6:28 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I'd also like --color=always on the command-line to override HGPLAIN=1
  et al, but that's more work, and this seems like a better fix. We've
  got a fair number of programs that actually want to automate hg and
  get colored output to users, so they should set HGPLAINEXCEPT=alias
  (what we usually recommend), but this has been breaking them because
  they then lose color.
  
  .. feature::
  
    The ``HGPLAINEXCEPT`` environment variable can now include ``color``
    to allow automatic output colorization in otherwise automated
    environments.

REPOSITORY
  rHG Mercurial

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

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

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel, spectral
phabricator - Nov. 29, 2017, 8:35 a.m.
xalep added a comment.


  You could also add `color` to the list of values described for `HGPLAINEXCEPT` in mercurial/help/environment.txt

REPOSITORY
  rHG Mercurial

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

To: durin42, #hg-reviewers
Cc: xalep, mercurial-devel
phabricator - Nov. 30, 2017, 9:26 p.m.
durin42 added a comment.


  In https://phab.mercurial-scm.org/D1532#26006, @xalep wrote:
  
  > You could also add `color` to the list of values described for `HGPLAINEXCEPT` in mercurial/help/environment.txt
  
  
  Nice catch, thanks!

REPOSITORY
  rHG Mercurial

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

To: durin42, #hg-reviewers
Cc: xalep, 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
@@ -29,6 +29,22 @@ 
   [status.unknown|? ][status.unknown|b/2/in_b_2]
   [status.unknown|? ][status.unknown|b/in_b]
   [status.unknown|? ][status.unknown|in_root]
+HGPLAIN disables color
+  $ HGPLAIN=1 hg status --color=debug
+  ? a/1/in_a_1
+  ? a/in_a
+  ? b/1/in_b_1
+  ? b/2/in_b_2
+  ? b/in_b
+  ? in_root
+HGPLAINEXCEPT=color does not disable color
+  $ HGPLAINEXCEPT=color hg status --color=debug
+  [status.unknown|? ][status.unknown|a/1/in_a_1]
+  [status.unknown|? ][status.unknown|a/in_a]
+  [status.unknown|? ][status.unknown|b/1/in_b_1]
+  [status.unknown|? ][status.unknown|b/2/in_b_2]
+  [status.unknown|? ][status.unknown|b/in_b]
+  [status.unknown|? ][status.unknown|in_root]
 
 hg status with template
   $ hg status -T "{label('red', path)}\n" --color=debug
diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -181,7 +181,7 @@ 
         configstyles(ui)
 
 def _modesetup(ui):
-    if ui.plain():
+    if ui.plain('color'):
         return None
     config = ui.config('ui', 'color')
     if config == 'debug':