0

I saw this question where the answerer uses termcap to define colors for less which then could be used for how man could be displayed. It said while termcap is obsolete, it's easier while terminfo is more complicated.

Could anybody share how this similar setting could be done using terminfo ?

$ cat ~/.LESS_TERMCAP 
export LESS_TERMCAP_mb=$(tput bold; tput setaf 2) # green
export LESS_TERMCAP_md=$(tput bold; tput setaf 6) # cyan
export LESS_TERMCAP_me=$(tput sgr0)
export LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4) # yellow on blue
export LESS_TERMCAP_se=$(tput rmso; tput sgr0)
export LESS_TERMCAP_us=$(tput smul; tput bold; tput setaf 7) # white
export LESS_TERMCAP_ue=$(tput rmul; tput sgr0)
export LESS_TERMCAP_mr=$(tput rev)
export LESS_TERMCAP_mh=$(tput dim)
export LESS_TERMCAP_ZN=$(tput ssubm)
export LESS_TERMCAP_ZV=$(tput rsubm)
export LESS_TERMCAP_ZO=$(tput ssupm)
export LESS_TERMCAP_ZW=$(tput rsupm) 

Obviously, the first thing that would change would be the name, it would be .LESS_TERMINFO. Apart from that have no idea.

I did try to read/parse terminfo page but didn't make much sense to me except for that it uses ncurses which IIRC also uses quite a bit of color, although I don't know if that's relevant or not.

Can anybody help share equivalent bits for .TERMINFO definitions for colors in less ?

shirish
  • 12,356
  • You should double-quote your $(…) to stop inadvertent filename expansion: LESS_TERMCAP_me="$(tput sgr0)" – bobbogo Feb 09 '21 at 15:22
  • Also, try $ LESS_TERMCAP_DEBUG=1 man man. less with show you the termcap annotations it is trying to use. – bobbogo Feb 09 '21 at 15:25

1 Answers1

3

It's identical: ncurses provides a termcap interface (which less uses) although the underlying terminal database is terminfo. Like almost all termcap applications, less doesn't really look closely at the syntax of the strings returned, only cares that it can ask for md (the termcap name corresponding to terminfo's bold).

less has a list of these termcap names which it reads using the tgetstr function (termcap...) at startup and allows you to override those values with environment variables named by the termcap name appended to LESS_TERMCAP_.

By the way, all of the tput commands in your example are using terminfo names. They're simply used to assign strings that less might read using the termcap interface.

Further reading:

Thomas Dickey
  • 76,765