aboutsummaryrefslogtreecommitdiff
path: root/bin/ls/print.c
diff options
context:
space:
mode:
authorJosef Karthauser <joe@FreeBSD.org>2001-12-28 18:14:50 +0000
committerJosef Karthauser <joe@FreeBSD.org>2001-12-28 18:14:50 +0000
commitc1499cf6cf6a8450fb0e7cdad9ea5276dee01e42 (patch)
tree4e2f85c1a98554aef44294b6d1d825a9fbcea2f5 /bin/ls/print.c
parentfb717773e7f9ae7cc644cc9bb4249f9d7469c2cf (diff)
downloadsrc-c1499cf6cf6a8450fb0e7cdad9ea5276dee01e42.tar.gz
src-c1499cf6cf6a8450fb0e7cdad9ea5276dee01e42.zip
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
Notes
Notes: svn path=/head/; revision=88583
Diffstat (limited to 'bin/ls/print.c')
-rw-r--r--bin/ls/print.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/bin/ls/print.c b/bin/ls/print.c
index dd586ccbf4d1..d03a2fdb7be0 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';
}
}
}