Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 May 2001 00:15:03 -0700 (MST)
From:      Jordan DeLong <fracture@allusion.net>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/27374: /bin/ls LSCOLORS modification to allow bold colors
Message-ID:  <200105160715.f4G7F3i50789@cx420564-b.tucson1.az.home.com>

next in thread | raw e-mail | index | archive | help

>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:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 16 00:20:01 PDT 2001
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200105160715.f4G7F3i50789>