From fracture@cx420564-b.tucson1.az.home.com  Wed May 16 00:17:59 2001
Return-Path: <fracture@cx420564-b.tucson1.az.home.com>
Received: from cx420564-b.tucson1.az.home.com (cx420564-b.tucson1.az.home.com [24.21.112.225])
	by hub.freebsd.org (Postfix) with ESMTP id 1D30037B422
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 16 May 2001 00:17:59 -0700 (PDT)
	(envelope-from fracture@cx420564-b.tucson1.az.home.com)
Received: (from fracture@localhost)
	by cx420564-b.tucson1.az.home.com (8.11.3/8.11.3) id f4G7F3i50789;
	Wed, 16 May 2001 00:15:03 -0700 (MST)
	(envelope-from fracture)
Message-Id: <200105160715.f4G7F3i50789@cx420564-b.tucson1.az.home.com>
Date: Wed, 16 May 2001 00:15:03 -0700 (MST)
From: Jordan DeLong <fracture@allusion.net>
Reply-To: Jordan DeLong <fracture@allusion.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: /bin/ls LSCOLORS modification to allow bold colors
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         27374
>Category:       bin
>Synopsis:       Added bold color to the /bin/ls color support
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 16 00:20:01 PDT 2001
>Closed-Date:    Fri Dec 28 10:17:13 PST 2001
>Last-Modified:  Fri Dec 28 10:18:45 PST 2001
>Originator:     Jordan DeLong
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
None
>Environment:
System: FreeBSD cx420564-b 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Tue Apr 24 08:33:58 GMT 2001 fracture@cx420564-b:/usr/src/sys/compile/HOBOIV i386
>Description:
        /bin/ls on freebsd has a limited support for colors where, if envoked with -G or
        if it finds CLICOLOR in the environment it uses the environment variable LSCOLORS
        to highlight differnt file types with differnt colors.

        the LSCOLORS variable is just a string of 0-7's for the fg and bg of the color, or
        and x to leave it alone.  This means that on, for example, the vga console, it is
        impossible to get a yellow color because yellow is really bold brown (color 3).

        I've made a little patch that allows the LSCOLORS to contain ),!,@,#,$,%,^,& (the
        shift of 0-7) to do a bold color for a particular file type.

	
>How-To-Repeat:
	for example, after applying the patch, this will do yellow for directories on syscons;
	% setenv LSCOLORS \#x6x50502xxxxx2124xxxx
	% ls -GF
>Fix:

--- ls-dist/extern.h	Tue Jul 11 23:19:14 2000
+++ ls/extern.h	Tue May 15 23:38:08 2001
@@ -54,6 +54,8 @@
 void	 parsecolors __P((char *cs));
 void     colorquit __P((int));
 
+extern  char    *enter_bold;
+extern  char    *attrs_off;
 extern  char    *ansi_fgcol;
 extern  char    *ansi_bgcol;
 extern  char    *ansi_coloff;
--- ls-dist/ls.c	Wed Aug 16 12:57:11 2000
+++ ls/ls.c	Tue May 15 23:38:33 2001
@@ -116,6 +116,8 @@
 #ifdef COLORLS
 int f_color;			/* add type in color for non-regular files */
 
+char *enter_bold;		/* sequence to set color to bold mode */
+char *attrs_off;		/* sequence to turn off attributes (bold mode, etc) */
 char *ansi_bgcol;		/* ANSI sequence to set background colour */
 char *ansi_fgcol;		/* ANSI sequence to set foreground colour */
 char *ansi_coloff;		/* ANSI sequence to reset colours */
@@ -282,6 +284,8 @@
 	    (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
 #ifdef COLORLS
 		if (tgetent(termcapbuf, getenv("TERM")) == 1) {
+			enter_bold = tgetstr("md", &bp);
+			attrs_off = tgetstr("me", &bp);
 			ansi_fgcol = tgetstr("AF", &bp);
 			ansi_bgcol = tgetstr("AB", &bp);
 
--- ls-dist/print.c	Tue Jul 11 23:19:14 2000
+++ ls/print.c	Tue May 15 23:38:16 2001
@@ -95,7 +95,12 @@
 
 char *defcolors = "4x5x2x3x1x464301060203";
 
-static int colors[C_NUMCOLORS][2];
+/* colors for file types */
+static struct {
+	int num[2];
+	int bold;
+} colors[C_NUMCOLORS];
+
 #endif
 
 void
@@ -383,14 +388,17 @@
 {
 	char *ansiseq;
 
-	if (colors[c][0] != -1) {
-		ansiseq = tgoto(ansi_fgcol, 0, colors[c][0]);
+	if (colors[c].bold)
+		tputs(enter_bold, 1, putch);
+
+	if (colors[c].num[0] != -1) {
+		ansiseq = tgoto(ansi_fgcol, 0, colors[c].num[0]);
 		if (ansiseq)
 			tputs(ansiseq, 1, putch);
 	}
 
-	if (colors[c][1] != -1) {
-		ansiseq = tgoto(ansi_bgcol, 0, colors[c][1]);
+	if (colors[c].num[1] != -1) {
+		ansiseq = tgoto(ansi_bgcol, 0, colors[c].num[1]);
 		if (ansiseq)
 			tputs(ansiseq, 1, putch);
 	}
@@ -401,6 +409,7 @@
 	int sig;
 {
 	tputs(ansi_coloff, 1, sig ? writech : putch);
+	tputs(attrs_off, 1, sig ? writech : putch);
 }
 
 static int
@@ -455,6 +464,8 @@
 	if (cs == NULL)    cs = ""; /* LSCOLORS not set */
 	len = strlen(cs);
 	for (i = 0 ; i < C_NUMCOLORS ; i++) {
+		colors[i].bold = 0;
+
 		if (len <= 2*i) {
 			c[0] = defcolors[2*i];
 			c[1] = defcolors[2*i+1];
@@ -464,17 +475,52 @@
 			c[1] = cs[2*i+1];
 		}
 		for (j = 0 ; j < 2 ; j++) {
+			/* shifted 0-7 (!, @, #, etc) do bold */
 			if ((c[j] < '0' || c[j] > '7') &&
-			    tolower((unsigned char)c[j]) != 'x') {
+			    tolower((unsigned char)c[j]) != 'x' &&
+			    c[j] != ')' && c[j] != '!' && c[j] != '@' &&
+			    c[j] != '#' && c[j] != '$' && c[j] != '%' &&
+			    c[j] != '^' && c[j] != '&') {
 				fprintf(stderr,
-					"error: invalid character '%c' in LSCOLORS env var\n",
-					c[j]);
-				c[j] = defcolors[2*i+j];
+				    "error: invalid character '%c' in LSCOLORS"
+				    " env var\n", c[j]);
+				c[j] = defcolors[2*i+j]-'0';
+			}
+
+			if (c[j] >= '0' && c[j] <= '7')
+				colors[i].num[j] = c[j]-'0';
+			else if (tolower((unsigned char)c[j] == 'x'))
+				colors[i].num[j] = -1;
+			else {
+				colors[i].bold = 1;
+
+				switch (c[j]) {
+				case ')':
+					colors[i].num[j] = 0;
+					break;
+				case '!':
+					colors[i].num[j] = 1;
+					break;
+				case '@':
+					colors[i].num[j] = 2;
+					break;
+				case '#':
+					colors[i].num[j] = 3;
+					break;
+				case '$':
+					colors[i].num[j] = 4;
+					break;
+				case '%':
+					colors[i].num[j] = 5;
+					break;
+				case '^':
+					colors[i].num[j] = 6;
+					break;
+				case '&':
+					colors[i].num[j] = 7;
+					break;
+				}
 			}
-			if (tolower((unsigned char)c[j]) == 'x')
-			    colors[i][j] = -1;
-			else
-			    colors[i][j] = c[j]-'0';
 		}
 	}
 }
>Release-Note:
>Audit-Trail:

From: Jordan DeLong <fracture@allusion.net>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/27374
Date: Wed, 16 May 2001 00:34:49 -0700

 --b5gNqxB1S1yM7hjW
 Content-Type: multipart/mixed; boundary="G4iJoqBmSsgzjUCe"
 Content-Disposition: inline
 
 
 --G4iJoqBmSsgzjUCe
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 I forgot to make appropriate modifications to the man page in my patch,
 so here's another patch for ls.1.
 
 --=20
 Jordan DeLong
 fracture@allusion.net
 
 
 --G4iJoqBmSsgzjUCe
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="ls.1.diff"
 
 --- ls.1.dist	Mon Mar  5 03:05:00 2001
 +++ ls.1	Wed May 16 00:30:30 2001
 @@ -443,23 +443,39 @@
  The color designators are as follows:
  .Pp
  .Bl -tag -width 4n -offset indent -compact
 -.It Sy 0
 +.It 0
  black
 -.It Sy 1
 +.It 1
  red
 -.It Sy 2
 +.It 2
  green
 -.It Sy 3
 +.It 3
  brown
 -.It Sy 4
 +.It 4
  blue
 -.It Sy 5
 +.It 5
  magenta
 -.It Sy 6
 +.It 6
  cyan
 -.It Sy 7
 +.It 7
  light grey
 -.It Sy x
 +.It )
 +bold black, usually shows up as dark grey
 +.It !
 +bold red
 +.It @
 +bold green
 +.It #
 +bold brown, usually shows up as yellow
 +.It $
 +bold blue
 +.It %
 +bold magenta
 +.It ^
 +bold cyan
 +.It &
 +bold light grey; looks like bright white
 +.It x
  default foreground or background
  .El
  .Pp
 
 --G4iJoqBmSsgzjUCe--
 
 --b5gNqxB1S1yM7hjW
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.4 (FreeBSD)
 Comment: For info see http://www.gnupg.org
 
 iEYEARECAAYFAjsCLZgACgkQDrrilS51AZ91DACbBq62AfOexfLCyXrdA+igyChi
 9rgAoIwkB3JIAy9x/BOk8A0hY+CmwHjb
 =/9Sd
 -----END PGP SIGNATURE-----
 
 --b5gNqxB1S1yM7hjW--

From: Peter Pentchev <roam@orbitel.bg>
To: Jordan DeLong <fracture@allusion.net>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/27374
Date: Wed, 16 May 2001 12:02:35 +0300

 On Wed, May 16, 2001 at 12:40:05AM -0700, Jordan DeLong wrote:
 > The following reply was made to PR bin/27374; it has been noted by GNATS.
 > 
 > From: Jordan DeLong <fracture@allusion.net>
 > To: bug-followup@freebsd.org
 > Cc:  
 > Subject: Re: bin/27374
 > Date: Wed, 16 May 2001 00:34:49 -0700
 > 
 >  --b5gNqxB1S1yM7hjW
 >  Content-Type: multipart/mixed; boundary="G4iJoqBmSsgzjUCe"
 >  Content-Disposition: inline
 >  
 >  
 >  --G4iJoqBmSsgzjUCe
 >  Content-Type: text/plain; charset=us-ascii
 >  Content-Disposition: inline
 >  Content-Transfer-Encoding: quoted-printable
 >  
 >  I forgot to make appropriate modifications to the man page in my patch,
 >  so here's another patch for ls.1.
 
 Is there a reason for your removing all the 'Sy' macros?  I think it is
 a Good Thing(tm) for the color specifiers to stand out..
 
 G'luck,
 Peter
 
 -- 
 I've heard that this sentence is a rumor.

From: Jordan DeLong <fracture@allusion.net>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/27374
Date: Wed, 16 May 2001 02:23:18 -0700

 --HcAYCG3uE/tztfnV
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 > Is there a reason for your removing all the 'Sy' macros?  I think it is
 > a Good Thing(tm) for the color specifiers to stand out..
 
 Nope, there's no good reason.  And I'd agree that it'd be nice (as well as
 consistent with the rest of the man page) to keep them there.  Unfortunatly
 I know very little about troff and mdoc stuff and when I added the ) and !
 lines they weren't standing out like the other ones, and I decided it'd be
 better to at least submit the neccesary content modifications to the manual
 page even if I couldn't figure that formatting part out.  So, if you know
 what I was doing wrong with the ) and ! (they just looked like .It Sy !),
 then they could probably be easily put back in.
 
 --=20
 Jordan DeLong
 fracture@allusion.net
 
 
 --HcAYCG3uE/tztfnV
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.4 (FreeBSD)
 Comment: For info see http://www.gnupg.org
 
 iEYEARECAAYFAjsCRwUACgkQDrrilS51AZ81KwCZAZbLlHq3O79QF+mg3VsZ8EsO
 regAniiu7UxYRPqVkmgPTj1gmoEr0ew7
 =axur
 -----END PGP SIGNATURE-----
 
 --HcAYCG3uE/tztfnV--
State-Changed-From-To: open->closed 
State-Changed-By: joe 
State-Changed-When: Fri Dec 28 10:17:13 PST 2001 
State-Changed-Why:  
I've committed bold colour support to -current.  Instead of 
using the suggested method, I instead chose to use the characters 
a-h to define the colours and the upper case variants for the 
bold versions of the same colours. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27374 
>Unformatted:
