aboutsummaryrefslogtreecommitdiffstats
path: root/ls-1-Allow-LSCOLORS-to-specify-an-underline.patch
blob: e072094c65c5298607c1d06c55c8ef8986f42dd0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
From 62bedad5fc7607ffbf76ab1f45b0aebd4b424289 Mon Sep 17 00:00:00 2001
From: Cameron Katri <me@cameronkatri.com>
Date: Fri, 28 May 2021 17:56:48 -0400
Subject: [PATCH] ls(1): Allow LSCOLORS to specify an underline

Summary: Allows capitalizing the background color character to unable an underline instead of bold, capitalizing the foreground color char will still do bold.

Differential Revision: https://reviews.freebsd.org/D30547
---
 bin/ls/extern.h |  1 +
 bin/ls/ls.1     | 19 +++++++++++--------
 bin/ls/ls.c     |  2 ++
 bin/ls/print.c  | 16 ++++++++++++++--
 4 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/bin/ls/extern.h b/bin/ls/extern.h
index 8dab2bcc9d8..247c2c4a1d5 100644
--- a/bin/ls/extern.h
+++ b/bin/ls/extern.h
@@ -66,6 +66,7 @@ extern	char	*ansi_bgcol;
 extern	char	*ansi_coloff;
 extern	char	*attrs_off;
 extern	char	*enter_bold;
+extern	char	*enter_underline;
 
 extern int	 colorflag;
 extern bool	 explicitansi;
diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
index 8510ca609cd..ef412dd2927 100644
--- a/bin/ls/ls.1
+++ b/bin/ls/ls.1
@@ -740,6 +740,7 @@ where
 is the foreground color and
 .Ar b
 is the background color.
+When the background color is capitalized, the text will underlined.
 .Pp
 The color designators are as follows:
 .Pp
@@ -761,23 +762,25 @@ cyan
 .It Sy h
 light grey
 .It Sy A
-bold black, usually shows up as dark grey
+bold or underlined black, usually shows up as dark grey
 .It Sy B
-bold red
+bold or underlined red
 .It Sy C
-bold green
+bold or underlined green
 .It Sy D
-bold brown, usually shows up as yellow
+bold or underlined brown, usually shows up as yellow
 .It Sy E
-bold blue
+bold or underlined blue
 .It Sy F
-bold magenta
+bold or underlined magenta
 .It Sy G
-bold cyan
+bold or underlined cyan
 .It Sy H
-bold light grey; looks like bright white
+bold or underlined light grey; looks like bright white
 .It Sy x
 default foreground or background
+.It Sy X
+default foreground or background, with an underline or bold
 .El
 .Pp
 Note that the above are standard
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 92575711251..8a30dd326b4 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -159,6 +159,7 @@ 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 */
+char *enter_underline;		/* ANSI sequence to enter underline mode */
 #endif
 
 static int rval;
@@ -485,6 +486,7 @@ main(int argc, char *argv[])
 			ansi_bgcol = tgetstr("AB", &bp);
 			attrs_off = tgetstr("me", &bp);
 			enter_bold = tgetstr("md", &bp);
+			enter_underline = tgetstr("us", &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 9a537418f7b..d07b83ed830 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -107,6 +107,7 @@ static const char *defcolors = "exfxcxdxbxegedabagacad";
 static struct {
 	int	num[2];
 	int	bold;
+	int	underline;
 } colors[C_NUMCOLORS];
 #endif
 
@@ -548,6 +549,8 @@ printcolor_termcap(Colors c)
 
 	if (colors[c].bold)
 		tputs(enter_bold, 1, putch);
+	if (colors[c].underline)
+		tputs(enter_underline, 1, putch);
 
 	if (colors[c].num[0] != -1) {
 		ansiseq = tgoto(ansi_fgcol, 0, colors[c].num[0]);
@@ -569,6 +572,8 @@ printcolor_ansi(Colors c)
 
 	if (colors[c].bold)
 		printf("1");
+	if (colors[c].underline)
+		printf(";4");
 	if (colors[c].num[0] != -1)
 		printf(";3%d", colors[c].num[0]);
 	if (colors[c].num[1] != -1)
@@ -667,6 +672,7 @@ parsecolors(const char *cs)
 	len = strlen(cs);
 	for (i = 0; i < (int)C_NUMCOLORS; i++) {
 		colors[i].bold = 0;
+		colors[i].underline = 0;
 
 		if (len <= 2 * (size_t)i) {
 			c[0] = defcolors[2 * i];
@@ -689,9 +695,15 @@ parsecolors(const char *cs)
 				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')
+				if (j == 1)
+					colors[i].underline = 1;
+				else
+					colors[i].bold = 1;
+			} else if (tolower((unsigned char)c[j]) == 'x') {
+				if (j == 1 && c[j] == 'X')
+					colors[i].underline = 1;
 				colors[i].num[j] = -1;
+			}
 			else {
 				warnx("invalid character '%c' in LSCOLORS"
 				    " env var", c[j]);
-- 
2.32.0