git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH] color: respect the $NO_COLOR convention

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 1, 2018, 17:10 UTC
Message-ID
<xmqqefl3iuvx.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<87zi3reoez.fsf@gmail.com>
Leah Neukirchen <leah@vuxu.org> writes:
> NO_COLOR (http://no-color.org/) is a comprehensive approach to disable
> colors by default for all tools:

The list of software that supports that "convention" is, eh, respectable. Is it really a "convention" yet, or yet another thing the user needs to worry about?

Show 10 quoted lines
> diff --git a/color.c b/color.c
> index d48dd947c..59e9c2459 100644
> --- a/color.c
> +++ b/color.c
> @@ -326,6 +326,8 @@ int git_config_colorbool(const char *var, const char *value)
>  
>  static int check_auto_color(void)
>  {
> +	if (getenv("NO_COLOR"))
> +		return 0;

Our convention often calls for CONFIG_VAR=false to mean "I do not want to see what CONFIG_VAR wants to do done", i.e.

	NO_COLOR=false git show

would show colored output if there is no other settings. But this code contradicts the convention, deliberately because that is what no-color.org wants. Makes me wonder if that convention is worth following in the first place.

>  	if (color_stdout_is_tty < 0)
>  		color_stdout_is_tty = isatty(1);
>  	if (color_stdout_is_tty || (pager_in_use() && pager_use_color)) {

According to no-color.org's FAQ #2, NO_COLOR should affect only the "default" behaviour, and should stay back if there is an explicit end-user configuration (or command line override). And this helper function is called only from want_color() when their is no such higher precedence setting, which is in line with the recommendation.

Which is good.
Previous: Leah NeukirchenNext: Leah Neukirchen
Message 2 of 6 in “color: respect the $NO_COLOR convention”
  1. color: respect the $NO_COLOR conventionLeah Neukirchen, Mar 1, 2018
  2. Junio C HamanoMar 1, 2018
  3. Leah NeukirchenMar 1, 2018
  4. Junio C HamanoMar 1, 2018
  5. brian m. carlsonMar 4, 2018
  6. Junio C HamanoMar 5, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.