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

Re: [PATCH] log --format: teach %C(auto,black) to paint it black only on terminals

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Dec 17, 2012, 11:44 UTC
Message-ID
<CACsJy8Dt4vEpO+EcAhWnko=XAajQ9OMgbDbVx78Eb=sZTjmKQA@mail.gmail.com>
In-Reply-To
<7vobhtm5pk.fsf_-_@alter.siamese.dyndns.org>
On Mon, Dec 17, 2012 at 3:40 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 7 quoted lines
> Traditionally, %C(color attr) always emitted the ANSI color
> sequence; it was up to the scripts that wanted to conditionally
> color their output to omit %C(...) specifier when they do not want
> colors.
>
> Optionally allow "auto," to be prefixed to the color, so that the
> output is colored iff it goes to the terminal.

I see "prefix" is clearly documented. Still it feels a bit unnatural that %C(red,auto) won't work. But we can make that case work later if somebody cares enough.

Show 7 quoted lines
>                         if (!end)
>                                 return 0;
> -                       color_parse_mem(placeholder + 2,
> -                                       end - (placeholder + 2),
> +                       if (!memcmp(begin, "auto,", 5)) {
> +                               if (!want_color(-1))
> +                                       return end - placeholder + 1;

This want_color() checks color.ui and only when color.ui = auto, it bothers to check if the output is tty. I think the document should say that "auto," (or maybe another name because it's not really auto) respects color.ui.

-- 
Duy
Previous: Junio C HamanoNext: Jeff King
Message 8 of 18 in “FW: Git log --graph doesn't output color when redirected”
  1. Srb, MichalDec 12, 2012
  2. Jeff KingDec 13, 2012
  3. Srb, MichalDec 13, 2012
  4. Nguyen Thai Ngoc DuyDec 15, 2012
  5. Jeff KingDec 15, 2012
  6. Junio C HamanoDec 15, 2012
  7. log --format: teach %C(auto,black) to paint it black only on terminalsJunio C Hamano, Dec 17, 2012
  8. Nguyen Thai Ngoc DuyDec 17, 2012
  9. Jeff KingDec 17, 2012
  10. Junio C HamanoDec 17, 2012
  11. Jeff KingDec 17, 2012
  12. Junio C HamanoDec 17, 2012
  13. Jeff KingDec 17, 2012
  14. 1/2 t6006: clean up whitespaceJunio C Hamano, Dec 17, 2012
  15. Jeff KingDec 17, 2012
  16. 1/2 t6006: clean up whitespaceJeff King, Dec 17, 2012
  17. 2/2 log --format: teach %C(auto,black) to respect color configJeff King, Dec 17, 2012
  18. Jeff KingDec 17, 2012

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.