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

Man pages have colors? A deep dive into groff

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 15, 2021, 22:10 UTC
Message-ID
<60a046bd83001_f4b0f20861@natae.notmuch>
Hi,

While I was doing the investigagion for my GNU_ROFF patch [1], I checked different versions of all the tools (asciidoc, asciidoctor, docbook, and groff).

When I tested my own compiled version of groff I noticed something weird: man pages have colors. This did not happen with the version shipped by Arch Linux.

I did notice the output generated by docbook stylesheets showed \m[blue], but no color showed up.

It turns out Arch Linux disables colors, and so does Debian, by disabling a feature called SGR. This happened about 10 years, and the rationale was that "it doesn't work correctly".

To enable SGR on these distributions you need to do GROFF_SGR=1, but that is not documented anywhere.

groff does check for a variable GROFF_NO_SGR, but it's the other way around: SGR is enabled unless that variable is set.

There's other ways your distribution might be screwing up with groff (for example Arch Linux converts \' to ', which is not correct), so you might want to check your shipped configuration in:

  /usr/share/groff/site-tmac/man.local
Unfortunately the colors in man pages leave a lot to be desired.
Here is a simple trick I've been using to show some custom colors:
  man() {
    GROFF_NO_SGR=1 \
    LESS_TERMCAP_md=$'\e[1;31m' \
    LESS_TERMCAP_me=$'\e[0m' \
    LESS_TERMCAP_us=$'\e[1;34m' \
    LESS_TERMCAP_ue=$'\e[0m' \
    LESS_TERMCAP_so=$'\e[1;35m' \
    LESS_TERMCAP_se=$'\e[0m' \
    command man "$@"
  }
Hopefully some of you might find this useful.
Cheers.
[1] https://lore.kernel.org/git/20210515115653.922902-2-felipe.contreras@gmail.com/
-- 
Felipe Contreras
Next: Ævar Arnfjörð Bjarmason
Message 1 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.