I’m likely over complicating this, but how do you enable color in man pages? I’ve tried exporting the below values in .bashrc and also setting my pager to most - neither seems to work.
.bashrc contains
Less Colors for Man Pages
export LESS_TERMCAP_mb=$’\E[01;31m’ # begin blinking
export LESS_TERMCAP_md=$’\E[01;38;5;74m’ # begin bold
export LESS_TERMCAP_me=$’\E[0m’ # end mode
export LESS_TERMCAP_se=$’\E[0m’ # end standout-mode
export LESS_TERMCAP_so=$’\E[38;5;246m’ # begin standout-mode - info box
export LESS_TERMCAP_ue=$’\E[0m’ # end underline
export LESS_TERMCAP_us=$’\E[04;38;5;146m’ # begin underline
ah crap - the last solution (compiling and installing most and export PAGER=most in .bashrc works now, resourcing didn’t work, just need to reopen terminal.)
Oddly, I found that one must install termcap for the export LESS_TERMCAP_md=$’\E01;38;5;74m’ # begin bold and such statements to have a chance or working.
Wow, weird
However, despite having termcap installed, exporting LESS_TERMCAP values still don’t work. Very odd.
paracelsus@Callandor:~> less --version
less 424
Copyright (C) 1984-2008 Mark Nudelman
Still rather weird - it works so easily on CentOS.
On Fri, 2009-05-22 at 00:16 +0000, LewsTherinTelemon wrote:
> Oddly, I found that one must install termcap for the export
> LESS_TERMCAP_md=$’\E01;38;5;74m’ # begin bold and such statements to
> have a chance or working.
>
> Wow, weird
>
> However, despite having termcap installed, exporting LESS_TERMCAP
> values still don’t work. Very odd.
>
> paracelsus@Callandor:~> less --version
> less 424
> Copyright (C) 1984-2008 Mark Nudelman
>
> Still rather weird - it works so easily on CentOS.
>
>
I just tried these:
export LESS_TERMCAP_mb=$’\E01;31m’ # begin blinking
export LESS_TERMCAP_md=$’\E01;31m’ # begin bold
export LESS_TERMCAP_me=$’\E0m’ # end mode
export LESS_TERMCAP_se=$’\E0m’ # end standout-mode
export LESS_TERMCAP_so=$’\E01;44;33m’ # begin standout-mode - info box
export LESS_TERMCAP_ue=$’\E0m’ # end underline
export LESS_TERMCAP_us=$’\E01;32m’ # begin underline
I should have stated that the env variables are displayed as below (as they just call the color escape sequences)
paracelsus@Callandor:~> env | grep -i term
LESS_TERMCAP_mb=
LESS_TERMCAP_md= (displays in red)
LESS_TERMCAP_me= (displays in blue)
TERM=xterm
LESS_TERMCAP_ue=
LESS_TERMCAP_us=
LESS_TERMCAP_so= (displays in grey)
LESS_TERMCAP_se=
COLORTERM=1
They show up okay for me when I show them with env | grep -i term but they don’t actually work in displaying the man pages with less as the pager, etc.
Looking at the man page for less, I don’t see any documentation that suggests that these kinds of environment variables are accepted by the standard less on openSUSE. Maybe they work in a modified or cutting edge version of less.
On Fri, 2009-05-22 at 22:26 +0000, LewsTherinTelemon wrote:
> Would you mind telling me what you have in your .bashrc and and
> /etc/profile exactly and the following displays?
>
> paracelsus@Callandor:~> env | grep -i term
> LESS_TERMCAP_mb=
> LESS_TERMCAP_md=
> LESS_TERMCAP_me=
> TERM=xterm
> LESS_TERMCAP_ue=
> LESS_TERMCAP_us=
> LESS_TERMCAP_so=
> LESS_TERMCAP_se=
> COLORTERM=1
>
> Strange as it should work but does not seem to for me. Must have
> something off in /etc/profile I am thinking.
Did you just cut and paste the lines from my message directly into your
shell? No need to try to put into your profile when just testing.
On Sat, 2009-05-23 at 01:26 +0000, ken yap wrote:
> Looking at the man page for less, I don’t see any documentation that
> suggests that these kinds of environment variables are accepted by the
> standard less on openSUSE. Maybe they work in a modified or cutting edge
> version of less.
It’s there, been there for many, many years. It’s just not documented.
I did not just paste the lines into bash - I have them in my .bashrc, and if I examine them, I see they are being defined and exported correctly, for example:
paracelsus@Callandor:~> env | grep -i term
LESS_TERMCAP_mb=
LESS_TERMCAP_md= (displays in red)
LESS_TERMCAP_me= (displays in blue)
TERM=xterm
LESS_TERMCAP_ue=
LESS_TERMCAP_us=
LESS_TERMCAP_so= (displays in grey)
LESS_TERMCAP_se=
COLORTERM=1
That is what is so odd about this. There they are, displayed in color, everything looks great. echo $PAGER shows less is set, and termcap is installed - but man pager are still not in color. (I did comment out unset termcap in /etc/profile - made no difference.)
Would you mind sharing your complete /etc/profile, .bashrc and what versions of termap and less you are using?
This is a very nice addition. I tested it on OS 10.3 with KDE 3.5.10 and on SLED 10 SP2 with Gnome 2.12.2. Both are stock installations. Colors are totally different (different machines, displays and systems), but no worries.
Ok… and I suspect the reason it’s not documented is because it is deprecated. Such settings would only work on one type of terminal and if you change to another type, the sequences would be wrong. Why not just set the terminal type and let less get the sequences from the termcap database? That’s the way termcap is supposed to work.
On Sat, 2009-05-23 at 08:36 +0000, ken yap wrote:
> cjcox;1990276 Wrote:
> > It’s there, been there for many, many years. It’s just not documented.
>
> Ok… and I suspect the reason it’s not documented is because it is
> deprecated. Such settings would only work on one type of terminal and if
> you change to another type, the sequences would be wrong. Why not just
> set the terminal type and let less get the sequences from the termcap
> database? That’s the way termcap is supposed to work.
I sort of agree. The naming is probably bad. You can always do the
direct tput queries to fill in the values… and thus adhere to the
spirit of the way things are supposed to work.
But apart from that, I’m not exactly sure how you could make it
more like it’s “supposed to work”. Unless you make some assumptions…
and then it’s your opinion vs. somebody else’s opinion with regards
to color properties (and just coding the variations of color handling
is somewhat problematic… sometimes you have to initialize, sometimes
not…etc… it may not be as simple as you think).
On Sat, 2009-05-23 at 05:16 +0000, LewsTherinTelemon wrote:
…
> Would you mind sharing your complete /etc/profile, .bashrc and what
> versions of termap and less you are using?
Actually, I didn’t want man color… so I simply pasted the variable
settings directly into my active shell to test.
I think I did it from an 11.0 box… TERM=xterm, I was using
a color capable terminal (konsole) and you do NOT need termcap,
just terminfo, I’m using terminfo-5.6
On Tue, 2009-05-26 at 15:11 +0000, cjcox wrote:
> On Sat, 2009-05-23 at 05:16 +0000, LewsTherinTelemon wrote:
> …
> > Would you mind sharing your complete /etc/profile, .bashrc and what
> > versions of termap and less you are using?
>
> Actually, I didn’t want man color… so I simply pasted the variable
> settings directly into my active shell to test.
>
> I think I did it from an 11.0 box… TERM=xterm, I was using
> a color capable terminal (konsole) and you do NOT need termcap,
> just terminfo, I’m using terminfo-5.6
You could make the argument that you don’t even need terminfo…
but that could be a big assumption.
(so let’s be safe)
Nice find cjcox! I have never researched into the roff, troff, groff text formatting systems - pretty interesting. I also found the you can enable SGR in when using the less pager by just exporting it with the -R option - which I think should achieve the same as export GROFF_NO_SGR=yes however this fails in practice
From the grotty man page:
" For SGR support, it is necessary to use the -R option of less(1) to disable the interpretation of grotty’s old output format.
Consequently, all programs which use less as the pager program have to pass this option to it. For man(1) in particular,
either add -R to the $PAGER environment variable, e.g.
PAGER="/usr/bin/less -R"
export PAGER
or use the -P option of man to set the pager executable and its options, or modify the configuration file of man in a similar
fashion."
And later:
“ENVIRONMENT
GROFF_NO_SGR
If set, the old drawing scheme for bold and underline (using the backspace character) is active. Colors are disabled.”
(It is interesting to note how to color codes in the grotty man page are themselves displayed between exporting GROFF_NO_SGR=yes and PAGER=less -r Both show color, but interpret the ANSI color codes differently.)
Problem indeed solved, export GROFF_NO_SGR=yes works very well - thanks for your input.
On Sat, 2009-05-30 at 03:06 +0000, LewsTherinTelemon wrote:
> Nice find cjcox! I have never researched into the roff, troff, groff
> text formatting systems - pretty interesting. I also found the you can
> enable SGR in when using the less pager by just exporting it with the -R
> option - which I think should achieve the same as export
> GROFF_NO_SGR=yes however this fails in practice
>
…snippy…
>
> Problem indeed solved, export GROFF_NO_SGR=yes works very well - thanks
> for your input.
It’s a mess… for fun also try changing your TERM
TERM=xterm-pcolor
man ls
You can uncompile using, TERM=xterm-pcolor infocmp
and then create your own terminal def with the colors you like… of
course it’s universal at this point if you change your TERM… use
tic to compile it (need ncurses-devel for that).
v24 6/3/85 Added ti,te terminal init & de-init.
(Thanks to Mike Kersenbrock)
v25 6/8/85 Added -U flag, standout mode underlining.
v26 6/9/85 Added -M flag.
Use underline termcap (us) if it exists.
More Codes
#if MSDOS_COMPILER
public int nm_fg_color; /* Color of normal text */
public int nm_bg_color;
public int bo_fg_color; /* Color of bold text */
public int bo_bg_color;
public int ul_fg_color; /* Color of underlined text */
public int ul_bg_color;
public int so_fg_color; /* Color of standout text */
public int so_bg_color;
public int bl_fg_color; /* Color of blinking text */
public int bl_bg_color;
static int sy_fg_color; /* Color of system text (before less) */
static int sy_bg_color;
#else
/*
* Strings passed to tputs() to do various terminal functions.
*/
static char
*sc_pad, /* Pad string */
*sc_home, /* Cursor home */
*sc_addline, /* Add line, scroll down following lines */
*sc_lower_left, /* Cursor to last line, first column */
*sc_return, /* Cursor to beginning of current line */
*sc_move, /* General cursor positioning */
*sc_clear, /* Clear screen */
*sc_eol_clear, /* Clear to end of line */
*sc_eos_clear, /* Clear to end of screen */
*sc_s_in, /* Enter standout (highlighted) mode */
*sc_s_out, /* Exit standout mode */
*sc_u_in, /* Enter underline mode */
*sc_u_out, /* Exit underline mode */
*sc_b_in, /* Enter bold mode */
*sc_b_out, /* Exit bold mode */
*sc_bl_in, /* Enter blink mode */
*sc_bl_out, /* Exit blink mode */
*sc_visual_bell, /* Visual bell (flash screen) sequence */
*sc_backspace, /* Backspace cursor */
*sc_s_keypad, /* Start keypad mode */
*sc_e_keypad, /* End keypad mode */
*sc_init, /* Startup terminal initialization */
*sc_deinit; /* Exit terminal de-initialization */
#endif