5

While inspecting the source code of less, I noticed that the included manpage (less.man) used terminal escape codes for showing bold text:

^[[1mNAME^[[0m
       less - opposite of more

^[[1mSYNOPSIS^[[0m
       ^[[1mless -?^[[0m
       ^[[1mless --help^[[0m
       ^[[1mless -V^[[0m
       ^[[1mless --version^[[0m
       ^[[1mless [-[+]aABcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]^[[0m

The command used to generate is apparently nroff -man:

$ head Makefile.aut 
# Makefile for authoring less.

EMAIL = bug-less@gnu.org
HOMEPAGE = http://www.greenwoodsoftware.com/less
SHELL = /bin/sh
RCS = rcs
NROFF = nroff -man

Yet, if I run nroff -man less.nro, I get the (usual) manpage output using backspaces:

N^HNA^HAM^HME^HE
       less - opposite of more

S^HSY^HYN^HNO^HOP^HPS^HSI^HIS^HS
       l^Hle^Hes^Hss^Hs -^H-?^H?
       l^Hle^Hes^Hss^Hs -^H--^H-h^Hhe^Hel^Hlp^Hp
       l^Hle^Hes^Hss^Hs -^H-V^HV
       l^Hle^Hes^Hss^Hs -^H--^H-v^Hve^Her^Hrs^Hsi^Hio^Hon^Hn

How do I generate the first form?

7

The "first form" is a... feature of groff. If your "nroff" is not a wrapper for groff, you will see only the second form.

The feature is referred to in the manual page for grotty (groff driver for typewriter-like devices):

By default, grotty emits SGR escape sequences (from ISO 6429, also called ANSI color escapes) to change text attributes (bold, italic, colors). This makes it possible to have eight different back-ground background ground and foreground colors; additionally, bold and italic attributes can be used at the same time (by using the BI font).

In practice, it does not work well, e.g., see how the same comment (post-processing those sequences) is misrendered here:

By default, grotty emits SGR escape sequences (from ISO 6429, also called ANSI color escapes) to change text attributes (bold, italic, colors). This makes it possible to have eight different M[green]backgroundM[] and m[red]foregroundm[] colors; additionally, bold and italic attributes can be used BI]at the same time] (by using the BI font).

and for that reason, some developers choose not to use it (e.g., this discussion from Emacs mailing list).

However, as the manual page says "By default". So, if you have groff, then it should be producing those escape sequences.

Packagers may apply patches to modify programs. A comment by @muru mentions the version in Debian (see bug reports and package page). The package changelog says this:

 -- Colin Watson <cjwatson@debian.org>  Sat, 27 Jul 2002 18:41:46 +0100
groff (1.18-1) unstable; urgency=low 

  * Disable the new ANSI colour/bold/underline escapes in nroff mode,
    because most pagers either fail to cope with it or need special options
    to do so. It can be re-enabled by editing /etc/groff/man.local and
    /etc/groff/mdoc.local, or by setting the environment variable GROFF_SGR
    to something non-empty.

However, the groff source does not mention GROFF_SGR; it has only references to GROFF_NO_SGR:

./NEWS:1108:  for the GROFF_NO_SGR environment variable also.
./NEWS:1450:o If the environment variable GROFF_NO_SGR is set, SGR output is disa...
./PROBLEMS:33:  1. Set the GROFF_NO_SGR environment variable.
./doc/webpage.ms:1920:.  URL #GROFF_NO_SGR GROFF_NO_SGR
./doc/webpagewebpage.ms:1922:. nop GROFF_NO_SGR
./doc/webpagewebpage.ms:2437:.TAG GROFF_NO_SGR        
./doc/webpagewebpage.ms:2439:If the environment variable GROFF_NO_SGR is set, SGR output is 
./src/devices/grotty/grotty.man:126:.B GROFF_NO_SGR
./src/devices/grotty/grotty.man:394:.B GROFF_NO_SGR
./src/devices/grotty/tty.cpp:864:  if (getenv("GROFF_NO_SGR"))

and the changelog (ChangeLog.118) gives no clue:

2002-02-12  Werner LEMBERG  <wl@gnu.org>

        * src/libs/libgroff/Makefile.sub (snprintf.o): Don't use
        $(COMPILE.c) to not include groff's assert.h.        
        * src/drivers/grotty/tty.cc (main): Add GROFF_NO_SGR environment
        variable.                           
        * NEWS, src/drivers/grotty/grotty.man: Document it. 

Setting GROFF_NO_SGR will not give SGR sequences (the manpage is correct). The Debian changelog comment refers to this chunk from /etc/groff/man.local, where Debian added a check for the GROFF_SGR variable:

.  \" Debian: Disable the use of SGR (ANSI colour) escape sequences by
.  \" grotty. 
.  if '\V[GROFF_SGR]'' \
.    output x X tty: sgr 0

and setting the environment variable does make it generate SGR sequences for bold, etc.

  • I do have groff and my nroff is a wrapper for groff (it apparently runs PATH="$GROFF_RUNTIME$PATH" groff -mtty-char $T $opts ${1+"$@"} – muru Nov 18 '15 at 22:49
  • Hmm. So it's a idea bad enough that the package maintainers disabled it. Ah, well. – muru Nov 19 '15 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.