Skip to content

Commit b6ec119

Browse files
authored
Merge pull request #2199 from Urgau/gha-logs-better-uncopy
Make timestamps visually uncopyable and simplify the impl
2 parents a983074 + afd212f commit b6ec119

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/gha_logs.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,30 @@ pub async fn gha_logs(
211211
<title>{job_name} - {owner}/{repo}@{short_sha}</title>
212212
{icon_status}
213213
<style>
214+
:root {{
215+
--timestamp-length: 28ch;
216+
}}
214217
body {{
215218
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
216219
background: #0C0C0C;
217220
color: #CCC;
218221
white-space: pre;
222+
padding-left: calc(var(--timestamp-length) + 1ch);
223+
margin: 0;
219224
}}
220225
.timestamp {{
221226
color: #848484;
222227
text-decoration: none;
228+
position: absolute;
229+
left: 0;
230+
width: var(--timestamp-length);
223231
}}
224232
.timestamp:hover {{
225233
text-decoration: underline;
226234
}}
235+
.timestamp::before {{
236+
content: attr(data-timestamp);
237+
}}
227238
.error-marker {{
228239
scroll-margin-bottom: 15vh;
229240
color: #e5534b;
@@ -275,9 +286,9 @@ body {{
275286
}}
276287
277288
// 3. Add a self-referencial anchor to all timestamps at the start of the lines
278-
const dateRegex = /^(\d{{4}}-\d{{2}}-\d{{2}}T\d{{2}}:\d{{2}}:\d{{2}}\.\d+Z)/gm;
279-
html = html.replace(dateRegex, (ts) =>
280-
`<a id="${{ts}}" href="#${{ts}}" class="timestamp">${{ts}}</a>`
289+
const dateRegex = /^(\d{{4}}-\d{{2}}-\d{{2}}T\d{{2}}:\d{{2}}:\d{{2}}\.\d+Z) /gm;
290+
html = html.replace(dateRegex, (match, ts) =>
291+
`<a id="${{ts}}" href="#${{ts}}" class="timestamp" data-timestamp="${{ts}}"></a>`
281292
);
282293
283294
// 4. Add a anchor around every "##[error]" string
@@ -337,11 +348,9 @@ body {{
337348
}});
338349
}}
339350
340-
// 8. Add a copy handler that force plain/text copy and removes the timestamps
341-
// from the copied selection.
342-
const dateRegexWithSpace = /^(\d{{4}}-\d{{2}}-\d{{2}}T\d{{2}}:\d{{2}}:\d{{2}}\.\d+Z )/gm;
351+
// 8. Add a copy handler that force plain/text copy
343352
document.addEventListener("copy", function(e) {{
344-
var text = window.getSelection().toString().replace(dateRegexWithSpace, '');
353+
var text = window.getSelection().toString();
345354
e.clipboardData.setData('text/plain', text);
346355
e.preventDefault();
347356
}});

0 commit comments

Comments
 (0)