1 From f873a0a04c981fbcc7879bcefe355fbbfd1a8adb Mon Sep 17 00:00:00 2001
2 From: Cameron Katri <me@cameronkatri.com>
3 Date: Fri, 28 May 2021 17:56:48 -0400
4 Subject: [PATCH] ls(1): Allow LSCOLORS to specify an underline
6 Summary: Allows capitalizing the background color character to unable an underline instead of bold, capitalizing the foreground color char will still do bold.
8 Differential Revision: https://reviews.freebsd.org/D30547
11 bin/ls/ls.1 | 19 +++++++++++--------
13 bin/ls/print.c | 16 ++++++++++++++--
14 4 files changed, 28 insertions(+), 10 deletions(-)
16 diff --git a/bin/ls/extern.h b/bin/ls/extern.h
17 index 8dab2bcc9d8..247c2c4a1d5 100644
20 @@ -66,6 +66,7 @@ extern char *ansi_bgcol;
21 extern char *ansi_coloff;
22 extern char *attrs_off;
23 extern char *enter_bold;
24 +extern char *enter_underline;
27 extern bool explicitansi;
28 diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
29 index 8510ca609cd..ef412dd2927 100644
32 @@ -740,6 +740,7 @@ where
33 is the foreground color and
35 is the background color.
36 +When the background color is capitalized, the text will underlined.
38 The color designators are as follows:
40 @@ -761,23 +762,25 @@ cyan
44 -bold black, usually shows up as dark grey
45 +bold or underlined black, usually shows up as dark grey
48 +bold or underlined red
51 +bold or underlined green
53 -bold brown, usually shows up as yellow
54 +bold or underlined brown, usually shows up as yellow
57 +bold or underlined blue
60 +bold or underlined magenta
63 +bold or underlined cyan
65 -bold light grey; looks like bright white
66 +bold or underlined light grey; looks like bright white
68 default foreground or background
70 +default foreground or background, with an underline or bold
73 Note that the above are standard
74 diff --git a/bin/ls/ls.c b/bin/ls/ls.c
75 index 338b3d1d2a2..67cb91fdcde 100644
78 @@ -161,6 +161,7 @@ char *ansi_fgcol; /* ANSI sequence to set foreground colour */
79 char *ansi_coloff; /* ANSI sequence to reset colours */
80 char *attrs_off; /* ANSI sequence to turn off attributes */
81 char *enter_bold; /* ANSI sequence to set color to bold mode */
82 +char *enter_underline; /* ANSI sequence to enter underline mode */
86 @@ -485,6 +486,7 @@ main(int argc, char *argv[])
87 ansi_bgcol = tgetstr("AB", &bp);
88 attrs_off = tgetstr("me", &bp);
89 enter_bold = tgetstr("md", &bp);
90 + enter_underline = tgetstr("us", &bp);
92 /* To switch colours off use 'op' if
93 * available, otherwise use 'oc', or
94 diff --git a/bin/ls/print.c b/bin/ls/print.c
95 index 9a537418f7b..da92668d5c5 100644
98 @@ -107,6 +107,7 @@ static const char *defcolors = "exfxcxdxbxegedabagacad";
103 } colors[C_NUMCOLORS];
106 @@ -548,6 +549,8 @@ printcolor_termcap(Colors c)
109 tputs(enter_bold, 1, putch);
110 + if (colors[c].underline)
111 + tputs(enter_underline, 1, putch);
113 if (colors[c].num[0] != -1) {
114 ansiseq = tgoto(ansi_fgcol, 0, colors[c].num[0]);
115 @@ -569,6 +572,8 @@ printcolor_ansi(Colors c)
119 + if (colors[c].underline)
121 if (colors[c].num[0] != -1)
122 printf(";3%d", colors[c].num[0]);
123 if (colors[c].num[1] != -1)
124 @@ -667,6 +672,7 @@ parsecolors(const char *cs)
126 for (i = 0; i < (int)C_NUMCOLORS; i++) {
128 + colors[i].underline = 0;
130 if (len <= 2 * (size_t)i) {
131 c[0] = defcolors[2 * i];
132 @@ -689,9 +695,15 @@ parsecolors(const char *cs)
133 colors[i].num[j] = c[j] - 'a';
134 else if (c[j] >= 'A' && c[j] <= 'H') {
135 colors[i].num[j] = c[j] - 'A';
136 - colors[i].bold = 1;
137 - } else if (tolower((unsigned char)c[j]) == 'x')
139 + colors[i].underline = 1;
141 + colors[i].bold = 1;
142 + } else if (tolower((unsigned char)c[j]) == 'x') {
143 + if (j && c[j] == 'X')
144 + colors[i].underline = 1;
145 colors[i].num[j] = -1;
148 warnx("invalid character '%c' in LSCOLORS"