diff --git a/mercurial/color.py b/mercurial/color.py --- a/mercurial/color.py +++ b/mercurial/color.py @@ -198,6 +198,13 @@ if config == 'debug': return 'debug' + # The http://no-color.org/ initiative wants to standardize on an environment + # variable to disable color. The value of this variable doesn't matter. + if 'NO_COLOR' in encoding.environ: + # Allow --color CLI argument to override NO_COLOR + if ui.configsource('ui', 'color') != '--color': + return None + auto = (config == 'auto') always = False if not auto and util.parsebool(config): 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,42 @@ [status.unknown|? ][status.unknown|b/in_b] (glob) [status.unknown|? ][status.unknown|in_root] +NO_COLOR disables color + + $ NO_COLOR=1 hg status + ? a/1/in_a_1 + ? a/in_a + ? b/1/in_b_1 + ? b/2/in_b_2 + ? b/in_b + ? in_root + + $ NO_COLOR=0 hg status + ? a/1/in_a_1 + ? a/in_a + ? b/1/in_b_1 + ? b/2/in_b_2 + ? b/in_b + ? in_root + + $ NO_COLOR= hg status + ? a/1/in_a_1 + ? a/in_a + ? b/1/in_b_1 + ? b/2/in_b_2 + ? b/in_b + ? in_root + +NO_COLOR is overridden by --color + + $ NO_COLOR=1 hg --color=always status + \x1b[0;35;1;4m? \x1b[0m\x1b[0;35;1;4ma/1/in_a_1\x1b[0m (esc) + \x1b[0;35;1;4m? \x1b[0m\x1b[0;35;1;4ma/in_a\x1b[0m (esc) + \x1b[0;35;1;4m? \x1b[0m\x1b[0;35;1;4mb/1/in_b_1\x1b[0m (esc) + \x1b[0;35;1;4m? \x1b[0m\x1b[0;35;1;4mb/2/in_b_2\x1b[0m (esc) + \x1b[0;35;1;4m? \x1b[0m\x1b[0;35;1;4mb/in_b\x1b[0m (esc) + \x1b[0;35;1;4m? \x1b[0m\x1b[0;35;1;4min_root\x1b[0m (esc) + hg status with template $ hg status -T "{label('red', path)}\n" --color=debug [red|a/1/in_a_1]