From mryan01@vapre.elision.org  Sat Jul 29 12:02:46 2000
Return-Path: <mryan01@vapre.elision.org>
Received: from vapre.elision.org (r83aap006377.sbo-smr.ma.cable.rcn.com [146.115.122.245])
	by hub.freebsd.org (Postfix) with ESMTP id 495B237B779
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 29 Jul 2000 12:02:44 -0700 (PDT)
	(envelope-from mryan01@vapre.elision.org)
Received: by vapre.elision.org (Postfix, from userid 1000)
	id A300A1931B; Sat, 29 Jul 2000 15:04:45 -0400 (EDT)
Message-Id: <20000729190445.A300A1931B@vapre.elision.org>
Date: Sat, 29 Jul 2000 15:04:45 -0400 (EDT)
From: mike ryan <msr+fbsd@elision.org>
Sender: mryan01@vapre.elision.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] ls refuses to output color to anything that's not a tty
X-Send-Pr-Version: 3.2

>Number:         20291
>Category:       bin
>Synopsis:       [PATCH] ls refuses to output color to anything that's not a tty
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    joe
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 29 12:10:02 PDT 2000
>Closed-Date:    Sat Aug 12 15:40:32 PDT 2000
>Last-Modified:  Sat Aug 12 15:42:20 PDT 2000
>Originator:     mike ryan
>Release:        FreeBSD 4.1-STABLE i386
>Organization:
>Environment:

	freebsd 4.1-stable

>Description:

	/bin/ls refuses to generate ansi color codes unless stdout is a
	terminal.  this prevents "ls -G | less -R" from working, for
	instance.

>How-To-Repeat:

	/bin/ls -G | /usr/bin/less -R

>Fix:

	the patch below forces color output if two -G flags are used.
	this allows "ls -GG | less -R" while preserving existing -G
	behavior.

Index: bin/ls/ls.c
===================================================================
RCS file: /home/ncvs/src/bin/ls/ls.c,v
retrieving revision 1.32.2.3
diff -c -r1.32.2.3 ls.c
*** bin/ls/ls.c	2000/07/12 06:19:14	1.32.2.3
--- bin/ls/ls.c	2000/07/29 18:19:19
***************
*** 120,125 ****
--- 120,126 ----
  char *ansi_fgcol;		/* ANSI sequence to set foreground colour */
  char *ansi_coloff;		/* ANSI sequence to reset colours */
  #endif
+ int num_opt_G = 0;		/* number of -G flags */
  
  int rval;
  
***************
*** 202,208 ****
  		        fts_options |= FTS_COMFOLLOW;
  			break;
  		case 'G':
! 			if (isatty(STDOUT_FILENO))
  #ifdef COLORLS
  				if (tgetent(termcapbuf, getenv("TERM")) == 1) {
  					ansi_fgcol = tgetstr("AF", &bp);
--- 203,209 ----
  		        fts_options |= FTS_COMFOLLOW;
  			break;
  		case 'G':
! 			if (num_opt_G++ || isatty(STDOUT_FILENO))
  #ifdef COLORLS
  				if (tgetent(termcapbuf, getenv("TERM")) == 1) {
  					ansi_fgcol = tgetstr("AF", &bp);

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->joe 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Mon Jul 31 02:46:13 PDT 2000 
Responsible-Changed-Why:  
Your mess, you clean it up. :-) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20291 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: mike ryan <msr+fbsd@elision.org>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/20291: [PATCH] ls refuses to output color to anything that's not a tty 
Date: Mon, 31 Jul 2000 11:45:58 +0200

 On Sat, 29 Jul 2000 15:04:45 -0400, mike ryan wrote:
 
 > 	the patch below forces color output if two -G flags are used.
 > 	this allows "ls -GG | less -R" while preserving existing -G
 > 	behavior.
 
 I think that this takes a bad situation and makes it worse.
 
 I think that if some serious thought had gone into colour support in the
 base system, it would be conditional on the value of an environment
 variable.  This would allow different values for this variable to
 control different requirements for colour support.
 
 Given the limitations of a command-line argument, I think that ls should
 just always spit colour out when the command-line argument is specified.
 
 The argument that most folks put -G in a shell alias is exactly the
 motivation for using an environment variable instead.
 
 But this isn't an environment variable; it's a command-line option
 and should be treated as such.  If the user provides the command-line
 argument that requires colour, then he should get colour, damnit. :-)
 
 Ciao,
 Sheldon.
 
State-Changed-From-To: open->closed 
State-Changed-By: joe 
State-Changed-When: Sat Aug 12 15:40:32 PDT 2000 
State-Changed-Why:  
Closed, please refer to PR#bin/20483. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20291 
>Unformatted:
