summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjoe <joe@FreeBSD.org>2001-12-28 18:14:50 +0000
committerjoe <joe@FreeBSD.org>2001-12-28 18:14:50 +0000
commitdcc10c8b7bb3b7cde69a46f68456a1ed92d1c8fc (patch)
tree4e2f85c1a98554aef44294b6d1d825a9fbcea2f5 /bin
parentb0e8a2af1f722c2ac2c13de4daeec09b9891e402 (diff)
downloadFreeBSD-src-dcc10c8b7bb3b7cde69a46f68456a1ed92d1c8fc.zip
FreeBSD-src-dcc10c8b7bb3b7cde69a46f68456a1ed92d1c8fc.tar.gz
Revamp the colour support to allow for bold characters. Colours
are now defined using the characters a-h and A-H for the bold variants. The old way using 0-7 for the colours still works, but prints a message asking the user to switch. PR: bin/27374
Diffstat (limited to 'bin')
-rw-r--r--bin/ls/extern.h2
-rw-r--r--bin/ls/ls.134
-rw-r--r--bin/ls/ls.c4
-rw-r--r--bin/ls/print.c54
4 files changed, 70 insertions, 24 deletions
diff --git a/bin/ls/extern.h b/bin/ls/extern.h
index 31e2ced..45b908d 100644
--- a/bin/ls/extern.h
+++ b/bin/ls/extern.h
@@ -57,4 +57,6 @@ void colorquit __P((int));
extern char *ansi_fgcol;
extern char *ansi_bgcol;
extern char *ansi_coloff;
+extern char *attrs_off;
+extern char *enter_bold;
#endif
diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
index 4aee305..be37844 100644
--- a/bin/ls/ls.1
+++ b/bin/ls/ls.1
@@ -461,22 +461,38 @@ is the background color.
The color designators are as follows:
.Pp
.Bl -tag -width 4n -offset indent -compact
-.It Sy 0
+.It Sy a
black
-.It Sy 1
+.It Sy b
red
-.It Sy 2
+.It Sy c
green
-.It Sy 3
+.It Sy d
brown
-.It Sy 4
+.It Sy e
blue
-.It Sy 5
+.It Sy f
magenta
-.It Sy 6
+.It Sy g
cyan
-.It Sy 7
+.It Sy h
light grey
+.It Sy A
+bold black, usually shows up as dark grey
+.It Sy B
+bold red
+.It Sy C
+bold green
+.It Sy D
+bold brown, usually shows up as yellow
+.It Sy E
+bold blue
+.It Sy F
+bold magenta
+.It Sy G
+bold cyan
+.It Sy H
+bold light grey; looks like bright white
.It Sy x
default foreground or background
.El
@@ -514,7 +530,7 @@ directory writable to others, with sticky bit
directory writable to others, without sticky bit
.El
.Pp
-The default is "4x5x2x3x1x464301060203", i.e. blue foreground and
+The default is "exfxcxdxbxegedabagacad", i.e. blue foreground and
default background for regular directories, black foreground and red
background for setuid executables, etc.
.It Ev LS_COLWIDTHS
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 86253d7..b2848c2 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -121,6 +121,8 @@ int f_color; /* add type in color for non-regular files */
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 */
+char *attrs_off; /* ANSI sequence to turn off attributes */
+char *enter_bold; /* ANSI sequence to set color to bold mode */
#endif
int rval;
@@ -289,6 +291,8 @@ main(argc, argv)
if (tgetent(termcapbuf, getenv("TERM")) == 1) {
ansi_fgcol = tgetstr("AF", &bp);
ansi_bgcol = tgetstr("AB", &bp);
+ attrs_off = tgetstr("me", &bp);
+ enter_bold = tgetstr("md", &bp);
/* To switch colours off use 'op' if
* available, otherwise use 'oc', or
diff --git a/bin/ls/print.c b/bin/ls/print.c
index dd586cc..d03a2fd 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -94,9 +94,14 @@ typedef enum Colors {
C_NUMCOLORS /* just a place-holder */
} Colors ;
-char *defcolors = "4x5x2x3x1x464301060203";
+char *defcolors = "exfxcxdxbxegedabagacad";
+
+/* colors for file types */
+static struct {
+ int num[2];
+ int bold;
+} colors[C_NUMCOLORS];
-static int colors[C_NUMCOLORS][2];
#endif
void
@@ -386,14 +391,17 @@ printcolor(c)
{
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);
}
@@ -404,6 +412,7 @@ endcolor(sig)
int sig;
{
tputs(ansi_coloff, 1, sig ? writech : putch);
+ tputs(attrs_off, 1, sig ? writech : putch);
}
static int
@@ -454,10 +463,13 @@ char *cs;
{
int i, j, len;
char c[2];
+ short legacy_warn = 0;
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];
@@ -467,17 +479,29 @@ char *cs;
c[1] = cs[2*i+1];
}
for (j = 0 ; j < 2 ; j++) {
- if ((c[j] < '0' || c[j] > '7') &&
- tolower((unsigned char)c[j]) != 'x') {
+ /* Legacy colours used 0-7 */
+ if (c[j] >= '0' && c[j] <= '7') {
+ colors[i].num[j] = c[j] - '0';
+ if (!legacy_warn) {
+ fprintf(stderr,
+ "warn: colors are now defined "
+ "using a-h instead of 0-9. "
+ "see manual page.\n");
+ }
+ legacy_warn = 1;
+ } else if (c[j] >= 'a' && c[j] <= 'h')
+ colors[i].num[j] = c[j] - 'a';
+ else if (c[j] >= 'A' && c[j] <= 'H') {
+ colors[i].num[j] = c[j] - 'A';
+ colors[i].bold = 1;
+ } else if (tolower((unsigned char)c[j] == 'x'))
+ colors[i].num[j] = -1;
+ else {
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]);
+ colors[i].num[j] = defcolors[2*i+j]-'0';
}
- if (tolower((unsigned char)c[j]) == 'x')
- colors[i][j] = -1;
- else
- colors[i][j] = c[j]-'0';
}
}
}
OpenPOWER on IntegriCloud