The summary says it all.
Created attachment 135500 [details, diff] Proposed patch for eselect This will disable colour codes if output is not going to a terminal.
Alternatively, one could follow the convention used in programs like "ls" or "grep", i.e. use an option --color=WHEN or --colour=WHEN: By default, color is not used to distinguish types of files. That is equivalent to using --color=none. Using the --color option without the optional WHEN argument is equivalent to using --color=always. With --color=auto, color codes are output only if standard output is con- nected to a terminal (tty).
Any news here? What solution should be taken, the simple one from attachment 135500 [details, diff], or the more elaborate one suggested in comment #2? I can prepare a patch for the latter if needed.
Some related notes on terminals and colors: The following should be used in addition to (not instead of) checking [[ -t 1 ]] tput queries terminfo to determine the capability of the terminal and output things like color escapes only if the terminal supports it. If terminfo is correct then tput's output is guaranteed to be term-safe, so it's safer to use tput instead of bare escapes. The BSD color convention is to set CLICOLOR=1 if you want colors, so if you can somehow check if a box is BSD, and CLICOLOR is unset or zero, it would be nice to automatically not print colors.
The following colour definitions (in output.bash.in) work for me: COLOUR_LIST_HEADER=$(tput -S <<<$'bold\nsetaf 2') COLOUR_LIST_LEFT=$(tput bold) COLOUR_LIST_RIGHT=$(tput sgr0) COLOUR_ERROR=$(tput -S <<<$'bold\nsetaf 1') COLOUR_NORMAL=$(tput sgr0) COLOUR_HI=$(tput -S <<<$'bold\nsetaf 4') COLOUR_WARN=$(tput -S <<<$'bold\nsetaf 1') For completeness, sys-libs/ncurses should be added to RDEPEND of eselect.
please do. another option for a release or -r3 material. your call.
Committed to trunk (r401) and 1.0.x branch (r402).
Another related problem: Function get_column_width() calls "stty size" even if output is redirected, and will return a width of 0 in some situations (e.g., inside an Emacs shell window). If there are no objections, I'll commit the following fix for output.bash: get_column_width() { if [[ -z "${COLS}" ]] ; then - COLS=( $(stty size 2>/dev/null) ) - is_number "${COLS[1]}" && COLS=${COLS[1]} || COLS=79 + COLS=79 + if [[ -t 1 ]] ; then + COLS=( $(stty size 2>/dev/null) ) + is_number "${COLS[1]}" && COLS=${COLS[1]} || COLS=79 + fi fi
(In reply to comment #8) > If there are no objections, I'll commit the following fix for output.bash: Committed to trunk (r423) and 1.0.x branch (r424).
Fixed in 1.0.12.