Skip to content

Commit 163cb1f

Browse files
authored
[llvm-cov] Add HTML dark theme support (llvm#93080)
Personally I use [cargo-llvm-cov](https://github.com/taiki-e/cargo-llvm-cov) which creates helpful HTML coverage reports, but they don't support a dynamic dark themes. I updated the styling to support both dark and bright color themes based on the browser preference. The bright theme should look similar to the current theme. I also improved some color contrasts (Firefox accessibility tool reported them) and ensured that line-number links keep their text-decoration. Things that both have `.tooltip` and `.red` look kinda odd as the coloring is now based on tinting with transparency. Given that the tooltip should always show 0 in such cases (otherwise it wouldn't be red) the tooltip could be removed there on the HTML generation, but that seemed out of scope for my style only change.
1 parent 3614bee commit 163cb1f

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const char *BeginHeader =
9090

9191
const char *CSSForCoverage =
9292
R"(.red {
93-
background-color: #ffd0d0;
93+
background-color: #f004;
9494
}
9595
.cyan {
9696
background-color: cyan;
@@ -104,38 +104,35 @@ pre {
104104
}
105105
.source-name-title {
106106
padding: 5px 10px;
107-
border-bottom: 1px solid #dbdbdb;
108-
background-color: #eee;
107+
border-bottom: 1px solid #8888;
108+
background-color: #0002;
109109
line-height: 35px;
110110
}
111111
.centered {
112112
display: table;
113113
margin-left: left;
114114
margin-right: auto;
115-
border: 1px solid #dbdbdb;
115+
border: 1px solid #8888;
116116
border-radius: 3px;
117117
}
118118
.expansion-view {
119-
background-color: rgba(0, 0, 0, 0);
120119
margin-left: 0px;
121120
margin-top: 5px;
122121
margin-right: 5px;
123122
margin-bottom: 5px;
124-
border: 1px solid #dbdbdb;
123+
border: 1px solid #8888;
125124
border-radius: 3px;
126125
}
127126
table {
128127
border-collapse: collapse;
129128
}
130129
.light-row {
131-
background: #ffffff;
132-
border: 1px solid #dbdbdb;
130+
border: 1px solid #8888;
133131
border-left: none;
134132
border-right: none;
135133
}
136134
.light-row-bold {
137-
background: #ffffff;
138-
border: 1px solid #dbdbdb;
135+
border: 1px solid #8888;
139136
border-left: none;
140137
border-right: none;
141138
font-weight: bold;
@@ -149,48 +146,35 @@ table {
149146
}
150147
.column-entry-yellow {
151148
text-align: left;
152-
background-color: #ffffd0;
153-
}
154-
.column-entry-yellow:hover, tr:hover .column-entry-yellow {
155-
background-color: #fffff0;
149+
background-color: #ff06;
156150
}
157151
.column-entry-red {
158152
text-align: left;
159-
background-color: #ffd0d0;
160-
}
161-
.column-entry-red:hover, tr:hover .column-entry-red {
162-
background-color: #fff0f0;
153+
background-color: #f004;
163154
}
164155
.column-entry-gray {
165156
text-align: left;
166-
background-color: #fbfbfb;
167-
}
168-
.column-entry-gray:hover, tr:hover .column-entry-gray {
169-
background-color: #f0f0f0;
157+
background-color: #fff4;
170158
}
171159
.column-entry-green {
172160
text-align: left;
173-
background-color: #d0ffd0;
174-
}
175-
.column-entry-green:hover, tr:hover .column-entry-green {
176-
background-color: #f0fff0;
161+
background-color: #0f04;
177162
}
178163
.line-number {
179164
text-align: right;
180-
color: #aaa;
181165
}
182166
.covered-line {
183167
text-align: right;
184-
color: #0080ff;
168+
color: #06d;
185169
}
186170
.uncovered-line {
187171
text-align: right;
188-
color: #ff3300;
172+
color: #d00;
189173
}
190174
.tooltip {
191175
position: relative;
192176
display: inline;
193-
background-color: #b3e6ff;
177+
background-color: #bef;
194178
text-decoration: none;
195179
}
196180
.tooltip span.tooltip-content {
@@ -227,12 +211,13 @@ th, td {
227211
vertical-align: top;
228212
padding: 2px 8px;
229213
border-collapse: collapse;
230-
border-right: solid 1px #eee;
231-
border-left: solid 1px #eee;
214+
border-right: 1px solid #8888;
215+
border-left: 1px solid #8888;
232216
text-align: left;
233217
}
234218
td pre {
235219
display: inline-block;
220+
text-decoration: inherit;
236221
}
237222
td:first-child {
238223
border-left: none;
@@ -241,13 +226,34 @@ td:last-child {
241226
border-right: none;
242227
}
243228
tr:hover {
244-
background-color: #f0f0f0;
229+
background-color: #eee;
245230
}
246231
tr:last-child {
247232
border-bottom: none;
248233
}
249-
tr:has(> td >a:target) > td.code > pre {
250-
background-color: #ffa;
234+
tr:has(> td >a:target) {
235+
background-color: #50f6;
236+
}
237+
a {
238+
color: inherit;
239+
}
240+
@media (prefers-color-scheme: dark) {
241+
body {
242+
background-color: #222;
243+
color: whitesmoke;
244+
}
245+
tr:hover {
246+
background-color: #111;
247+
}
248+
.covered-line {
249+
color: #39f;
250+
}
251+
.uncovered-line {
252+
color: #f55;
253+
}
254+
.tooltip {
255+
background-color: #068;
256+
}
251257
}
252258
)";
253259

0 commit comments

Comments
 (0)