ls(1): Allow LSCOLORS to specify an underline
Allows capitalizing the background color character to enable an underline instead of bold, capitalizing the foreground color char will still do bold. Differential Revision: https://reviews.freebsd.org/D30547
This commit is contained in:
parent
da0c0e0121
commit
97c31821eb
@ -66,6 +66,7 @@ extern char *ansi_bgcol;
|
|||||||
extern char *ansi_coloff;
|
extern char *ansi_coloff;
|
||||||
extern char *attrs_off;
|
extern char *attrs_off;
|
||||||
extern char *enter_bold;
|
extern char *enter_bold;
|
||||||
|
extern char *enter_underline;
|
||||||
|
|
||||||
extern int colorflag;
|
extern int colorflag;
|
||||||
extern bool explicitansi;
|
extern bool explicitansi;
|
||||||
|
19
bin/ls/ls.1
19
bin/ls/ls.1
@ -740,6 +740,7 @@ where
|
|||||||
is the foreground color and
|
is the foreground color and
|
||||||
.Ar b
|
.Ar b
|
||||||
is the background color.
|
is the background color.
|
||||||
|
When the background color is capitalized, the text will underlined.
|
||||||
.Pp
|
.Pp
|
||||||
The color designators are as follows:
|
The color designators are as follows:
|
||||||
.Pp
|
.Pp
|
||||||
@ -761,23 +762,25 @@ cyan
|
|||||||
.It Sy h
|
.It Sy h
|
||||||
light grey
|
light grey
|
||||||
.It Sy A
|
.It Sy A
|
||||||
bold black, usually shows up as dark grey
|
bold or underlined black, usually shows up as dark grey
|
||||||
.It Sy B
|
.It Sy B
|
||||||
bold red
|
bold or underlined red
|
||||||
.It Sy C
|
.It Sy C
|
||||||
bold green
|
bold or underlined green
|
||||||
.It Sy D
|
.It Sy D
|
||||||
bold brown, usually shows up as yellow
|
bold or underlined brown, usually shows up as yellow
|
||||||
.It Sy E
|
.It Sy E
|
||||||
bold blue
|
bold or underlined blue
|
||||||
.It Sy F
|
.It Sy F
|
||||||
bold magenta
|
bold or underlined magenta
|
||||||
.It Sy G
|
.It Sy G
|
||||||
bold cyan
|
bold or underlined cyan
|
||||||
.It Sy H
|
.It Sy H
|
||||||
bold light grey; looks like bright white
|
bold or underlined light grey; looks like bright white
|
||||||
.It Sy x
|
.It Sy x
|
||||||
default foreground or background
|
default foreground or background
|
||||||
|
.It Sy X
|
||||||
|
default foreground or background, with an underline or bold
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
Note that the above are standard
|
Note that the above are standard
|
||||||
|
@ -159,6 +159,7 @@ char *ansi_fgcol; /* ANSI sequence to set foreground colour */
|
|||||||
char *ansi_coloff; /* ANSI sequence to reset colours */
|
char *ansi_coloff; /* ANSI sequence to reset colours */
|
||||||
char *attrs_off; /* ANSI sequence to turn off attributes */
|
char *attrs_off; /* ANSI sequence to turn off attributes */
|
||||||
char *enter_bold; /* ANSI sequence to set color to bold mode */
|
char *enter_bold; /* ANSI sequence to set color to bold mode */
|
||||||
|
char *enter_underline; /* ANSI sequence to enter underline mode */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int rval;
|
static int rval;
|
||||||
@ -485,6 +486,7 @@ main(int argc, char *argv[])
|
|||||||
ansi_bgcol = tgetstr("AB", &bp);
|
ansi_bgcol = tgetstr("AB", &bp);
|
||||||
attrs_off = tgetstr("me", &bp);
|
attrs_off = tgetstr("me", &bp);
|
||||||
enter_bold = tgetstr("md", &bp);
|
enter_bold = tgetstr("md", &bp);
|
||||||
|
enter_underline = tgetstr("us", &bp);
|
||||||
|
|
||||||
/* To switch colours off use 'op' if
|
/* To switch colours off use 'op' if
|
||||||
* available, otherwise use 'oc', or
|
* available, otherwise use 'oc', or
|
||||||
|
@ -106,7 +106,8 @@ static const char *defcolors = "exfxcxdxbxegedabagacad";
|
|||||||
/* colors for file types */
|
/* colors for file types */
|
||||||
static struct {
|
static struct {
|
||||||
int num[2];
|
int num[2];
|
||||||
int bold;
|
bool bold;
|
||||||
|
bool underline;
|
||||||
} colors[C_NUMCOLORS];
|
} colors[C_NUMCOLORS];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -548,6 +549,8 @@ printcolor_termcap(Colors c)
|
|||||||
|
|
||||||
if (colors[c].bold)
|
if (colors[c].bold)
|
||||||
tputs(enter_bold, 1, putch);
|
tputs(enter_bold, 1, putch);
|
||||||
|
if (colors[c].underline)
|
||||||
|
tputs(enter_underline, 1, putch);
|
||||||
|
|
||||||
if (colors[c].num[0] != -1) {
|
if (colors[c].num[0] != -1) {
|
||||||
ansiseq = tgoto(ansi_fgcol, 0, colors[c].num[0]);
|
ansiseq = tgoto(ansi_fgcol, 0, colors[c].num[0]);
|
||||||
@ -569,6 +572,8 @@ printcolor_ansi(Colors c)
|
|||||||
|
|
||||||
if (colors[c].bold)
|
if (colors[c].bold)
|
||||||
printf("1");
|
printf("1");
|
||||||
|
if (colors[c].underline)
|
||||||
|
printf(";4");
|
||||||
if (colors[c].num[0] != -1)
|
if (colors[c].num[0] != -1)
|
||||||
printf(";3%d", colors[c].num[0]);
|
printf(";3%d", colors[c].num[0]);
|
||||||
if (colors[c].num[1] != -1)
|
if (colors[c].num[1] != -1)
|
||||||
@ -666,7 +671,8 @@ parsecolors(const char *cs)
|
|||||||
cs = ""; /* LSCOLORS not set */
|
cs = ""; /* LSCOLORS not set */
|
||||||
len = strlen(cs);
|
len = strlen(cs);
|
||||||
for (i = 0; i < (int)C_NUMCOLORS; i++) {
|
for (i = 0; i < (int)C_NUMCOLORS; i++) {
|
||||||
colors[i].bold = 0;
|
colors[i].bold = false;
|
||||||
|
colors[i].underline = false;
|
||||||
|
|
||||||
if (len <= 2 * (size_t)i) {
|
if (len <= 2 * (size_t)i) {
|
||||||
c[0] = defcolors[2 * i];
|
c[0] = defcolors[2 * i];
|
||||||
@ -689,10 +695,15 @@ parsecolors(const char *cs)
|
|||||||
colors[i].num[j] = c[j] - 'a';
|
colors[i].num[j] = c[j] - 'a';
|
||||||
else if (c[j] >= 'A' && c[j] <= 'H') {
|
else if (c[j] >= 'A' && c[j] <= 'H') {
|
||||||
colors[i].num[j] = c[j] - 'A';
|
colors[i].num[j] = c[j] - 'A';
|
||||||
colors[i].bold = 1;
|
if (j == 1)
|
||||||
} else if (tolower((unsigned char)c[j]) == 'x')
|
colors[i].underline = true;
|
||||||
|
else
|
||||||
|
colors[i].bold = true;
|
||||||
|
} else if (tolower((unsigned char)c[j]) == 'x') {
|
||||||
|
if (j == 1 && c[j] == 'X')
|
||||||
|
colors[i].underline = true;
|
||||||
colors[i].num[j] = -1;
|
colors[i].num[j] = -1;
|
||||||
else {
|
} else {
|
||||||
warnx("invalid character '%c' in LSCOLORS"
|
warnx("invalid character '%c' in LSCOLORS"
|
||||||
" env var", c[j]);
|
" env var", c[j]);
|
||||||
colors[i].num[j] = -1;
|
colors[i].num[j] = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user