# HG changeset patch # User Pierre-Yves David # Date 1493748114 -7200 # Node ID 9a85ea1daf49b7785b8448834e3e944a14fb991f # Parent 8e1708947496b2247338246e1bcac028e93a0f37 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 -r 8e1708947496 -r 9a85ea1daf49 mercurial/color.py --- 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 diff -r 8e1708947496 -r 9a85ea1daf49 mercurial/help/color.txt --- 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. diff -r 8e1708947496 -r 9a85ea1daf49 mercurial/help/config.txt --- 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 diff -r 8e1708947496 -r 9a85ea1daf49 tests/test-diff-color.t --- 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 <> $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 diff -r 8e1708947496 -r 9a85ea1daf49 tests/test-pager-legacy.t --- 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 < [ui] > color = yes + > formatted = yes > [color] > mode = ansi > EOF diff -r 8e1708947496 -r 9a85ea1daf49 tests/test-pager.t --- 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 < [ui] > color = yes + > formatted = yes > [color] > mode = ansi > EOF diff -r 8e1708947496 -r 9a85ea1daf49 tests/test-status-color.t --- 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 <> $HGRCPATH > [ui] > color = always + > formatted = yes > [color] > mode = ansi > EOF