Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 184604

Summary: Gentoo doesn't have colors in man pages
Product: Gentoo Linux Reporter: Robert Buchholz (RETIRED) <rbu>
Component: [OLD] UnspecifiedAssignee: Gentoo's Team for Core System packages <base-system>
Status: RESOLVED FIXED    
Severity: enhancement CC: kentnl, tove
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
URL: http://nion.modprobe.de/blog/archives/572-less-colors-for-man-pages.html
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: /etc/profile.d/setcolors.sh

Description Robert Buchholz (RETIRED) gentoo-dev 2007-07-08 14:36:27 UTC
Gentoo sets up colors for all kinds of applications, as grep, ls, less and for PS1, but not for man.

According to the URL above, this can easily be done by setting LESS_TERMCAP variables which could be a default in Gentoo. The attached script could be included in /etc/profile.d/

Reproducible: Always

Steps to Reproduce:
1. Log in
2. man gcc
3. 

Actual Results:  
See no colors.

Expected Results:  
Some colors.
Comment 1 Robert Buchholz (RETIRED) gentoo-dev 2007-07-08 14:37:09 UTC
Created attachment 124238 [details]
/etc/profile.d/setcolors.sh
Comment 2 Roy Marples (RETIRED) gentoo-dev 2007-07-09 06:23:00 UTC
Would be better to attach it to 07less in /etc/env.d/ I suppose.
This just puts escape codes on my screen instead of the actual colours though - any other step required?
Comment 3 Robert Buchholz (RETIRED) gentoo-dev 2007-07-09 08:36:47 UTC
It didn't work via env.d for me either. But profile.d did fine.
Can this be some kind of escaping / parsing problem when creating profile.env?
Comment 4 Roy Marples (RETIRED) gentoo-dev 2007-07-09 11:33:41 UTC
Yes, it's a bug with env-update.

baselayout-2's version of env-update will work with this in alpha4, hopefully portage team can update their env-update to work too. Basically if an env.d entry value begins with $ we just add it as it stands instead of attempting to quote it.
Comment 5 SpanKY gentoo-dev 2007-07-09 20:12:52 UTC
i was poking around cygwin because it has colors enabled but it doesnt have these LESS envvars set nor does it patch less ... anyone care to investigate how it is handled there ?  otherwise, adding this sort of thing to Gentoo by default sounds good (although i'd change the default color scheme to better line up with default Gentoo colors)
Comment 6 Robert Buchholz (RETIRED) gentoo-dev 2007-07-09 22:24:38 UTC
(In reply to comment #5)
> i was poking around cygwin because it has colors enabled but it doesnt have
> these LESS envvars set nor does it patch less ... anyone care to investigate
> how it is handled there ? 

I believe they changed their "cygwin" TERMINFO file to contain the colours[1], because if I unset the TERM, the colours disappear (which they don't if I do the same thing in Gentoo with the environment variables set).

I'm not too good at picking colors, so maybe you (or someone else) can propose a more Gentoo like scheme.

[1] See description in http://nion.modprobe.de/blog/archives/569-colored-manpages.html
Comment 7 Zac Medico gentoo-dev 2007-07-11 20:33:59 UTC
(In reply to comment #4)
> baselayout-2's version of env-update will work with this in alpha4, hopefully
> portage team can update their env-update to work too. Basically if an env.d
> entry value begins with $ we just add it as it stands instead of attempting to
> quote it.

This is fixed in portage-2.1.3_rc8.
Comment 8 Roy Marples (RETIRED) gentoo-dev 2007-08-03 07:32:04 UTC
And in baselayout-2.0.0_rc1

Right, how do we want to handle this then? USE flag for less?
Comment 9 Robert Buchholz (RETIRED) gentoo-dev 2007-08-03 10:26:19 UTC
I guess it's a sane default to have (or does it break anything?).
On the other hand, /etc/env.d is not config_protected, so users' changes would be overwritten.

Is there another way than a USE flag, because I did not think USE flags are there to change the "default config" of a package. How could one easily revert the setting permanently without it being a USE flag?
Comment 10 Petteri Räty (RETIRED) gentoo-dev 2007-08-03 14:53:54 UTC
(In reply to comment #9)
> I guess it's a sane default to have (or does it break anything?).
> On the other hand, /etc/env.d is not config_protected, so users' changes would
> be overwritten.
> 

Users can config protect /etc/env.d if they want to protect their changes. They can also just have a later file overwrite the value set by ebuilds.
Comment 11 SpanKY gentoo-dev 2007-08-03 15:34:42 UTC
users should never modify things in /etc/env.d/

these are default env vars so users are free to do the same exact thing they always do: put it in ~/.profile or whatever for your shell
Comment 12 SpanKY gentoo-dev 2007-08-25 18:53:04 UTC
hrm, the side affect here is that `env` can cause confusion as it includes all of color stuff ...
Comment 13 Robert Buchholz (RETIRED) gentoo-dev 2007-11-11 15:34:50 UTC
So, what's the status here?
What steps are needed to implement this in baselayout or somewhere else?
Comment 14 SpanKY gentoo-dev 2007-11-11 18:59:36 UTC
the status is as in #12 ... it can be done, but it inserts colors into your environment which screws you up when doing `env`

it could be circumvented with a wrapper, but that's clearly undesirable
Comment 15 Robert Buchholz (RETIRED) gentoo-dev 2007-11-11 20:49:57 UTC
(In reply to comment #14)
> the status is as in #12 ... it can be done, but it inserts colors into your
> environment which screws you up when doing `env`

Would you agree that this is a bug in env? It should either reset colours in every new line or escape the characters, as bash's `set' is doing. If so, we could move the discussion upstream.
Comment 16 SpanKY gentoo-dev 2007-11-12 06:03:49 UTC
i would not say it's a bug in the `env` command ... it does not care about the content of environment variables, it merely shows you the key<->value binding

you could try asking upstream about injecting a "normal color" escape sequence before each variable name, but i doubt it'll get accepted ...
Comment 17 Torsten Veller (RETIRED) gentoo-dev 2007-11-13 06:17:06 UTC
Maybe I am confused and don't get the point at all but I've always had colored man pages:

Resources (see /usr/share/X11/app-defaults/XTerm-color)
*colorBDMode: on
*colorULMode: on
*colorBD: red
*colorUL: green

(Works with my xterm and rxvt-unicode)
Comment 18 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-03-31 19:13:21 UTC
rbu:
so the last status on this was that putting colours in the ENV screwed up the `env` output. Perhaps pursue the terminfo changes instead?
Comment 19 Rafał Kłys 2011-01-27 19:35:16 UTC
Here's another way of doing it, maybe in safer way?, from Arch wiki (https://wiki.archlinux.org/index.php/Man_Page):

man() {
	env \
		LESS_TERMCAP_mb=$(printf "\e[1;37m") \
		LESS_TERMCAP_md=$(printf "\e[1;37m") \
		LESS_TERMCAP_me=$(printf "\e[0m") \
		LESS_TERMCAP_se=$(printf "\e[0m") \
		LESS_TERMCAP_so=$(printf "\e[1;47;30m") \
		LESS_TERMCAP_ue=$(printf "\e[0m") \
		LESS_TERMCAP_us=$(printf "\e[0;36m") \
			man "$@"
}
Comment 20 Kent Fredric (IRC: kent\n) (RETIRED) gentoo-dev 2011-02-15 12:11:13 UTC
(In reply to comment #19)
> Here's another way of doing it, maybe in safer way?, from Arch wiki
> (https://wiki.archlinux.org/index.php/Man_Page):
> 
> man() {
>         env \
>                 LESS_TERMCAP_mb=$(printf "\e[1;37m") \
>                 LESS_TERMCAP_md=$(printf "\e[1;37m") \
>                 LESS_TERMCAP_me=$(printf "\e[0m") \
>                 LESS_TERMCAP_se=$(printf "\e[0m") \
>                 LESS_TERMCAP_so=$(printf "\e[1;47;30m") \
>                 LESS_TERMCAP_ue=$(printf "\e[0m") \
>                 LESS_TERMCAP_us=$(printf "\e[0;36m") \
>                         man "$@"
> }
> 

As seen here: http://unix.stackexchange.com/questions/6010/colored-man-pages-not-working-on-gentoo 

GROFF_NO_SGR=1 may have to be added to force it to work. 

Personally, I'd much rather a wrapper to man that injected \m[red] in the code before shipping it off to groff, then it will JustWork the way the git man pages currently do.

grep '\m\[' /usr/share/man/man1/*

for a list of man-pages that already have colour support without needing anything changed.
Comment 21 SpanKY gentoo-dev 2015-08-22 00:04:54 UTC
few more reasons to not go the env route:
- it puts the env in all programs, not just man
- that means every time you use `less`, it changes the display, not just `man`

along those lines, i don't think we want to mess with termcap.  that too affects all output and not just when using man.

that really only leaves the $MANPAGER route.
Comment 22 SpanKY gentoo-dev 2015-08-30 03:17:38 UTC
i've written a smaller wrapper that takes care of setting the right color variables.  it does this via the MANPAGER env var.
http://gitweb.gentoo.org/repo/gentoo.git/commit/?id=65f60cb497c44cc45f0e02f3661cfce3c5661e2c

the man-db package has grown a USE=manpager flag and tweaked the config file so that the color shows up by default.

let's see who starts complaining ;).