3

Is it possible, and if so how, to have colour/bold/italic characters in man pages while using w3m?

Another pager (most) does have some limited colour support but is not as versatile as w3m. I know that less does have colour support as shown here.

  • 2
    May depend on the man implementation you use. man from the mandb package has a --html switch. When using it $BROWSER is used for paging instead of $MANPAGER or $PAGER. – manatwork Dec 04 '13 at 11:15
  • @manatwork: I did not know that. This is quiet nice but still no colours... I feel that I should up vote your contribution! ^_~ – Sardathrion - against SE abuse Dec 04 '13 at 11:56
  • The man pages will still be formatted with bold and italic. Try lynx. It colors bold in red and italic in blue. (Not sure, but I think those are configurable.) BROWSER=lynx man -H man: http://i.stack.imgur.com/zIRaw.png – manatwork Dec 04 '13 at 12:30
  • Short form of --html with mandb is -H ;) Lynx is a good idea. – goldilocks Dec 04 '13 at 13:02
  • 1
    The colors are configurable; go to O)ptions, scroll to the bottom to where it says "View the file lynx.cfg" -> "color-style configuration". Except you can't edit lynx.cfg in lynx, lol. The system wide is /etc/lynx.cfg. @manatwork : You should put this up as an answer, it's great. – goldilocks Dec 04 '13 at 13:13
  • 3
  • Why would one use w3m as pager for a manual page? Are you talking about HTML manual pages? Also: Not less has color support, but the terminal. less can only send control sequences to the terminal to make that switch colors. Finally: Manual pages do not use colors; they use attributes like bold, underline, or italics. – U. Windl Jun 22 '22 at 07:28

1 Answers1

2

Not quite the answer you were looking for, but it might be a better one.

mandb is an implementation of man that will format man pages in HTML. It was written by someone at Redhat and is I think now the standard on all .rpm based systems, but available to install as a replacement for the old man on Debian, Ubuntu, et. al.

Using mandb, man -H whatever will format the page in HTML and send it to $BROWSER. There are a few man pages where this goes screwy (such as gcc), but most of them are fine. It's also sometimes problematic with google-chrome.

That's a great feature, but most of the time I can't be bothered -- I'd rather just glance through the page in a terminal. Thanks to lynx, a text mode web browser, you can sort of get the best of both worlds. I don't want $BROWSER to be lynx generally, so:

#!/bin/bash

BROWSER=lynx
man -H $@

And call this mnlx or something. mandb creates a tmp file to do this, so you could speed things up by caching the HTML versions and using those when available -- but that's a longer script...

The really nice thing about this is mandb also adds an index with links to each section at the top, e.g.:

                           BASH                BASH (p1 of 121)
   NAME
   SYNOPSIS
   COPYRIGHT
   DESCRIPTION
   OPTIONS
   ARGUMENTS
   INVOCATION
   DEFINITIONS
   RESERVED WORDS
   SHELL GRAMMAR
   COMMENTS
   QUOTING
   PARAMETERS
   EXPANSION
   REDIRECTION
   ALIASES
   FUNCTIONS
   [...]

The man page proper follows this. As manatwork indicates in the comments, italic and bold appear as red and (bold) blue in lynx; normal text is white, links are green, the current link is bold yellow.

goldilocks
  • 87,661
  • 30
  • 204
  • 262
  • +1. Not the direct answer to my question but still a great answer to my problem! Thank you. – Sardathrion - against SE abuse Dec 04 '13 at 17:03
  • I think this answer is rather wrong: mandb does not format manual pages; groff (nroff, troff) does. As the manual page for man states: "This option will cause groff to produce HTML output..." – U. Windl Jun 22 '22 at 07:35
  • That's the mandb man page, right? Ie., mandb uses groff to produce HTML, because of course man pages in their source form use groff/troff formatting. While this is interesting and perhaps of significance in some contexts, I don't see how delving into the details of the implementation are relevant here, just a simple explication of the interface. – goldilocks Jun 22 '22 at 13:15