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

Re: Man pages have colors? A deep dive into groff

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 18, 2021, 04:27 UTC
Message-ID
<60a3422b9556c_14d1bc2082f@natae.notmuch>
In-Reply-To
<xmqqim3g4ys5.fsf@gitster.g>
Junio C Hamano wrote:
> Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 14 quoted lines
> > Why not use color.pager?
> 
> I dug a bit to refresh my memory and it turns out that the reason we
> should not do so is because it means something totally different.
> 
> color.[ch] defines want_color() that applications like "diff" and
> "log" can use to see if the application is configured to paint its
> output in colors.
> 
> When that layer says for that particular application it should be
> decided automatically, then we call into color.c::check_auto_color()
> which is the only user of pager_use_color (which is set from the
> color.pager configuration variable).  The purpose of that call is to
> ask if the pager is capable of colors.
That is not true. check_auto_color() returns 1 when the fd is a tty.

For example advice() would indirectly call check_auto_color() and no pager is involved.

Inside the help built-in want_color(GIT_COLOR_UNKNOWN) will always return 1 (unless you do something like `git help git > file`).

pager_use_color is completely ignored in this case.

It's used only when 1) the fd is not a tty, 2) it's stdout, 3) git is using a pager... Only _then_ it checks for pager_use_color (color.pager).

So no; the first purpose of check_auto_color() is to find out if the fd is capable of showing colors, secondary, if we are using a pager, then check the user configuration.

In the case we are using a pager it's not check if the pager is capable of colors, the pager could be capable of colors and yet the user would disable them: it's the check for the user preference.

> So in short, the color.pager is about "is the pager capable of
> colors?"
That's not the case.
Even the documentation says so:
  color.pager::
    A boolean to enable/disable colored output when the pager is in
    use (default is true).
> and the color.ui (and color.<cmd>) is about "does the user
> wants output from <cmd> in color?"
> Tying it directly to "color.pager" is wrong.

Why? color.pager is to enable/disable colored output when a pager is in use.

The fact that it's man executing the pager and not git makes no difference to the user.

Cheers.
-- 
Felipe Contreras
Previous: Junio C HamanoNext: Jeff King
Message 8 of 15 in “Man pages have colors? A deep dive into groff”
  1. Felipe ContrerasMay 15, 2021
  2. Ævar Arnfjörð BjarmasonMay 17, 2021
  3. Junio C HamanoMay 17, 2021
  4. Felipe ContrerasMay 17, 2021
  5. Randall S. BeckerMay 17, 2021
  6. Felipe ContrerasMay 17, 2021
  7. Junio C HamanoMay 18, 2021
  8. Felipe ContrerasMay 18, 2021
  9. Jeff KingMay 18, 2021
  10. Felipe ContrerasMay 18, 2021
  11. Junio C HamanoMay 18, 2021
  12. brian m. carlsonMay 18, 2021
  13. Junio C HamanoMay 18, 2021
  14. Felipe ContrerasMay 18, 2021
  15. Felipe ContrerasMay 18, 2021

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.