git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Subject: Man pages have colors? A deep dive into groff
Date: Sat, 15 May 2021 17:10:05 -0500	[thread overview]
Message-ID: <60a046bd83001_f4b0f20861@natae.notmuch> (raw)

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

             reply	other threads:[~2021-05-15 22:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-15 22:10 Felipe Contreras [this message]
2021-05-17 16:48 ` Man pages have colors? A deep dive into groff Ævar Arnfjörð Bjarmason
2021-05-17 19:28   ` Junio C Hamano
2021-05-17 22:44     ` Felipe Contreras
2021-05-17 22:54       ` Randall S. Becker
2021-05-17 23:33         ` Felipe Contreras
2021-05-18  1:27       ` Junio C Hamano
2021-05-18  4:27         ` Felipe Contreras
2021-05-18  7:16           ` Jeff King
2021-05-18 13:21             ` Felipe Contreras
2021-05-18 14:27             ` Junio C Hamano
2021-05-18  1:28   ` brian m. carlson
2021-05-18  2:12     ` Junio C Hamano
2021-05-18  4:35       ` Felipe Contreras
2021-05-18  4:31     ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=60a046bd83001_f4b0f20861@natae.notmuch \
    --to=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).