esearch should suppress the output of color codes if stdout is being
piped to another application, such as 'less'. The '--nocolor' option
allows you to do this, but it ought to be automatic. Here is a simple
patch to implement this behavior.
Steps to Reproduce:
1. Install esearch and initialize its database
2. Invoke esearch and pipe its output to less:
'esearch gentoo | less'
3. The output will contain color codes which less
won't display correctly
[ Results for search key : ESC[01mgentooESC[39;49;00m ]
[ Applications found : ESC[01m16ESC[39;49;00m ]
[ Masked ]ESC[39;49;00m
[ Results for search key : gentoo ]
[ Applications found : 16 ]
* app-admin/gentoo-bugger [ Masked ]
Here's a very simple patch to esearch.py (from esearch 0.7) to suppress color if
stdout is not a tty:
--- esearch.py+ 2004-09-26 04:56:23.000000000 -0500
+++ esearch.py 2005-09-05 10:40:23.000000000 -0500
@@ -154,6 +154,8 @@
error("The version of the esearch index is out of date, please run " +
+if sys.stdout.isatty() == 0:
Created attachment 67690 [details, diff]
Simple patch to suppress color if stdout is not a tty
By the way, this bug was automatically assigned to:
Portage Utitilities Team <firstname.lastname@example.org>
"Utilities" is misspelled.
The Irony here is that bug 42115 wants the exact opposite for emerge. What if
your pager accepts ANSI color codes? Why should color be turned off
automagically? Why can't you just use --nocolor?
less can be configured to show color and i enjoy that feature ...
If you don't want color, use --nocolor.