color: turn 'ui.color' into a boolean (auto or off) stable
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Tue, 02 May 2017 20:01:54 +0200
branchstable
changeset 32102 9a85ea1daf49
parent 32101 8e1708947496
child 32103 9a98023ac8db
color: turn 'ui.color' into a boolean (auto or off) Previously, 'ui.color=yes' meant "always show color", While "ui.color=auto" meant "use color automatically when it appears sensible". This feels problematic to some people because if an administrator has disabled color with "ui.color=off", and a user turn it back on using "color=on", it will get surprised (because it breaks their output when redirected to a file.) This patch changes ui.color=true to only move the default value of --color from "never" to "auto". I'm not really in favor of this changes as I suspect the above case will be pretty rare and I would rather keep the logic simpler. However, I'm providing this patch to help the 4.2 release in the case were others decide to make this changes. Users that want to force colors without specifying --color on the command line can use the 'ui.formatted' config knob, which had to be enabled in a handful of tests for this patch. Nice summary table (credit: Augie Fackler) That is, before this patch: +--------------------+--------------------+--------------------+ | | not a tty | a tty | | | --color not set | --color not set | | | | | +--------------------+--------------------+--------------------+ | [ui] | | | | color (not set) | no color | no color | | | | | +--------------------+--------------------+--------------------+ | [ui] | | | | color = auto | no color | color | | | | | +--------------------+--------------------+--------------------+ | [ui] | | | | color = yes | *color* | color | | | | | +--------------------+--------------------+--------------------+ | [ui] | | | | color = no | no color | no color | | | | | +--------------------+--------------------+--------------------+ (if --color is specified, it always clobbers the setting in [ui]) and after this patch: +--------------------+--------------------+--------------------+ | | not a tty | a tty | | | --color not set | --color not set | | | | | +--------------------+--------------------+--------------------+ | [ui] | | | | color (not set) | no color | no color | | | | | +--------------------+--------------------+--------------------+ | [ui] | | | | color = auto | no color | color | | | | | +--------------------+--------------------+--------------------+ | [ui] | | | | color = yes | *no color* | color | | | | | +--------------------+--------------------+--------------------+ | [ui] | | | | color = no | no color | no color | | | | | +--------------------+--------------------+--------------------+ (if --color is specified, it always clobbers the setting in [ui])
mercurial/color.py
mercurial/help/color.txt
mercurial/help/config.txt
tests/test-diff-color.t
tests/test-pager-legacy.t
tests/test-pager.t
tests/test-status-color.t
--- a/mercurial/color.py	Mon May 01 16:43:43 2017 +0200
+++ b/mercurial/color.py	Tue May 02 20:01:54 2017 +0200
@@ -193,7 +193,14 @@
         return 'debug'
 
     auto = (config == 'auto')
-    always = not auto and util.parsebool(config)
+    always = False
+    if not auto and util.parsebool(config):
+        # we want the config to behave like a boolean, "on" is actually auto
+        if ui.configsource('ui', 'color') == '--color':
+            always = True
+        else:
+            auto = True
+
     if not always and not auto:
         return None
 
--- a/mercurial/help/color.txt	Mon May 01 16:43:43 2017 +0200
+++ b/mercurial/help/color.txt	Tue May 02 20:01:54 2017 +0200
@@ -5,15 +5,15 @@
 other commands have analogous colors. It is possible to customize
 these colors.
 
-To enable color (default) use::
+To enable color (default) whenever possible use::
 
   [ui]
-  color = auto
+  color = yes
 
 To disable color use::
 
   [ui]
-  color = never
+  color = no
 
 See :hg:`help config.ui.color` for details.
 
--- a/mercurial/help/config.txt	Mon May 01 16:43:43 2017 +0200
+++ b/mercurial/help/config.txt	Tue May 02 20:01:54 2017 +0200
@@ -1884,9 +1884,9 @@
     By default, the first bundle advertised by the server is used.
 
 ``color``
-    When to colorize output. Possible value are Boolean, "always", "auto",
-    "never", or "debug". (default: "auto"). "auto" will use color
-    whenever it seems possible. See :hg:`help color` for details.
+    When to colorize output. Possible value are Boolean ("yes" or "no"), or
+    "debug". (default: "yes"). "yes" will use color whenever it seems possible.
+    See :hg:`help color` for details.
 
 ``commitsubrepos``
     Whether to commit modified subrepositories when committing the
--- a/tests/test-diff-color.t	Mon May 01 16:43:43 2017 +0200
+++ b/tests/test-diff-color.t	Tue May 02 20:01:54 2017 +0200
@@ -3,6 +3,7 @@
   $ cat <<EOF >> $HGRCPATH
   > [ui]
   > color = always
+  > formatted = always
   > [color]
   > mode = ansi
   > EOF
@@ -49,6 +50,38 @@
    a
    c
 
+(check that 'ui.color=yes' match '--color=auto')
+
+  $ hg diff --nodates --config ui.formatted=no
+  diff -r cf9f4ba66af2 a
+  --- a/a
+  +++ b/a
+  @@ -2,7 +2,7 @@
+   c
+   a
+   a
+  -b
+  +dd
+   a
+   a
+   c
+
+(check that 'ui.color=no' disable color)
+
+  $ hg diff --nodates --config ui.formatted=yes --config ui.color=no
+  diff -r cf9f4ba66af2 a
+  --- a/a
+  +++ b/a
+  @@ -2,7 +2,7 @@
+   c
+   a
+   a
+  -b
+  +dd
+   a
+   a
+   c
+
 --unified=2
 
   $ hg diff --nodates -U 2
--- a/tests/test-pager-legacy.t	Mon May 01 16:43:43 2017 +0200
+++ b/tests/test-pager-legacy.t	Tue May 02 20:01:54 2017 +0200
@@ -161,6 +161,7 @@
   $ cat >> $HGRCPATH <<EOF
   > [ui]
   > color = yes
+  > formatted = yes
   > [color]
   > mode = ansi
   > EOF
--- a/tests/test-pager.t	Mon May 01 16:43:43 2017 +0200
+++ b/tests/test-pager.t	Tue May 02 20:01:54 2017 +0200
@@ -142,6 +142,7 @@
   $ cat >> $HGRCPATH <<EOF
   > [ui]
   > color = yes
+  > formatted = yes
   > [color]
   > mode = ansi
   > EOF
--- a/tests/test-status-color.t	Mon May 01 16:43:43 2017 +0200
+++ b/tests/test-status-color.t	Tue May 02 20:01:54 2017 +0200
@@ -1,6 +1,7 @@
   $ cat <<EOF >> $HGRCPATH
   > [ui]
   > color = always
+  > formatted = yes
   > [color]
   > mode = ansi
   > EOF