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

Bug 104932

Summary: esearch: Minor patch to disable color if stdout is not a TTY
Product: Portage Development Reporter: tar
Component: Third-Party ToolsAssignee: Portage Tools Team <tools-portage>
Status: RESOLVED WONTFIX    
Severity: enhancement CC: davidpeter
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: Simple patch to suppress color if stdout is not a tty

Description tar 2005-09-05 11:40:46 UTC
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.

Reproducible: Always
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

Actual Results:  
[ Results for search key : ESC[01mgentooESC[39;49;00m ]
[ Applications found : ESC[01m16ESC[39;49;00m ]

ESC[32;01m*ESC[39;49;00m  ESC[01mapp-admin/gentoo-buggerESC[39;49;00mESC[31;01m
[ Masked ]ESC[39;49;00m


Expected Results:  
[ 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 @@
 def outofdateerror():
     error("The version of the esearch index is out of date, please run " +
green("eupdatedb"))

+if sys.stdout.isatty() == 0:
+    nocolor()

 try:
     sys.path.append(esearchdbdir)
Comment 1 tar 2005-09-05 11:41:42 UTC
Created attachment 67690 [details, diff]
Simple patch to suppress color if stdout is not a tty
Comment 2 tar 2005-09-05 11:43:40 UTC
By the way, this bug was automatically assigned to:

Portage Utitilities Team <tools-portage@gentoo.org>

"Utilities" is misspelled.
Comment 3 Alec Warner (RETIRED) archtester gentoo-dev Security 2005-10-12 01:22:14 UTC
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?
Comment 4 SpanKY gentoo-dev 2005-10-12 06:23:04 UTC
less can be configured to show color and i enjoy that feature ...
Comment 5 Alec Warner (RETIRED) archtester gentoo-dev Security 2006-04-23 21:41:45 UTC
If you don't want color, use --nocolor.