# HG changeset patch
# User Pierre-Yves David <pierre-yves.da...@ens-lyon.org>
# Date 1493748114 -7200
#      Tue May 02 20:01:54 2017 +0200
# Branch stable
# Node ID d862ebc515bfc09f2d9e6c32a509092b6434fbd1
# Parent  7c76f3923b6a4fd6a35a9b498be15b9c549955eb
# EXP-Topic color
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull 
https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r d862ebc515bf
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])

diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -193,7 +193,14 @@ def _modesetup(ui):
         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
 
diff --git a/mercurial/help/color.txt b/mercurial/help/color.txt
--- a/mercurial/help/color.txt
+++ b/mercurial/help/color.txt
@@ -5,15 +5,15 @@ in red, while the status command shows m
 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.
 
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1881,9 +1881,9 @@ User interface controls.
     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
diff --git a/tests/test-diff-color.t b/tests/test-diff-color.t
--- a/tests/test-diff-color.t
+++ b/tests/test-diff-color.t
@@ -3,6 +3,7 @@ Setup
   $ cat <<EOF >> $HGRCPATH
   > [ui]
   > color = always
+  > formatted = always
   > [color]
   > mode = ansi
   > EOF
@@ -49,6 +50,38 @@ default context
    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
diff --git a/tests/test-pager-legacy.t b/tests/test-pager-legacy.t
--- a/tests/test-pager-legacy.t
+++ b/tests/test-pager-legacy.t
@@ -161,6 +161,7 @@ even though stdout is no longer a tty.
   $ cat >> $HGRCPATH <<EOF
   > [ui]
   > color = yes
+  > formatted = yes
   > [color]
   > mode = ansi
   > EOF
diff --git a/tests/test-pager.t b/tests/test-pager.t
--- a/tests/test-pager.t
+++ b/tests/test-pager.t
@@ -142,6 +142,7 @@ even though stdout is no longer a tty.
   $ cat >> $HGRCPATH <<EOF
   > [ui]
   > color = yes
+  > formatted = yes
   > [color]
   > mode = ansi
   > EOF
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
@@ -1,6 +1,7 @@
   $ cat <<EOF >> $HGRCPATH
   > [ui]
   > color = always
+  > formatted = yes
   > [color]
   > mode = ansi
   > EOF
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to