From owner-freebsd-bugs Wed May 16 0:20:10 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id C887737B43E for ; Wed, 16 May 2001 00:20:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f4G7K1d38256; Wed, 16 May 2001 00:20:01 -0700 (PDT) (envelope-from gnats) 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 ; 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 Reply-To: Jordan DeLong To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: bin/27374: /bin/ls LSCOLORS modification to allow bold colors Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >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