Skip to content

Commit 35a45c5

Browse files
committed
Add copy button for log entries
Easy way to copy error (and other) messages
1 parent b1e5448 commit 35a45c5

File tree

2 files changed

+107
-8
lines changed

2 files changed

+107
-8
lines changed

Assets/WebGLTemplates/Develop/debug-console.css

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,62 @@
1010
font-family: "Lucida Console", "Courier New", monospace;
1111
}
1212

13-
#debugConsole p {
13+
#debugConsole .entry {
1414
padding: 8px 4px;
1515
color: rgb(41, 41, 41);
1616
background-color: rgba(230, 230, 230, 0.9);
17+
display: flex;
18+
justify-content: space-between;
19+
border-bottom: 1px solid #3d3d3d;
1720
}
1821

19-
#debugConsole p.info {
22+
#debugConsole .entry.info {
2023
color: rgb(41, 50, 60);
2124
background-color: rgba(172, 204, 224, 0.9);
2225
}
2326

24-
#debugConsole p.warn {
27+
#debugConsole .entry.warn {
2528
color: rgb(82, 70, 3);
2629
background-color: rgba(231, 196, 41, 0.9);
2730
}
2831

29-
#debugConsole .error {
32+
#debugConsole .entry.error {
3033
color: rgb(97, 15, 9);
3134
background-color: rgba(221, 46, 46, 0.9);
3235
}
3336

37+
#debugConsole .entry .copy-button {
38+
position: relative;
39+
flex-shrink: 0;
40+
width: 20px;
41+
height: 20px;
42+
cursor: pointer;
43+
border: 0;
44+
background: none;
45+
}
46+
47+
#debugConsole .entry .copy-button:before {
48+
content: 'copied';
49+
position: absolute;
50+
bottom: 0;
51+
right: 10px;
52+
width: 60px;
53+
height: 20px;
54+
padding-top: 4px;
55+
text-align: center;
56+
color: white;
57+
background: #333;
58+
border-radius: 10px;
59+
opacity: 0;
60+
transition: all 0.3s ease-out;
61+
}
62+
63+
#debugConsole .entry .copy-button.active:before {
64+
opacity: 1;
65+
right: 30px;
66+
transition: all 0.2s ease-out;
67+
}
68+
3469
/* Debug console toggle button */
3570
.debugToggleMenu {
3671
z-index: 101;
@@ -93,4 +128,48 @@
93128

94129
#startupTime dt:after{
95130
content: ':';
96-
}
131+
}
132+
133+
/* Copy icon from https://css.gg/copy */
134+
.gg-copy {
135+
box-sizing: border-box;
136+
position: relative;
137+
display: block;
138+
transform: scale(var(--ggs,1));
139+
width: 14px;
140+
height: 18px;
141+
border: 2px solid;
142+
margin-top: -4px
143+
}
144+
145+
.gg-copy::after,
146+
.gg-copy::before {
147+
content: "";
148+
display: block;
149+
box-sizing: border-box;
150+
position: absolute
151+
}
152+
153+
.gg-copy::before {
154+
background:
155+
linear-gradient( to left,
156+
currentColor 5px, transparent 0)
157+
no-repeat right top/5px 2px,
158+
linear-gradient( to left,
159+
currentColor 5px, transparent 0)
160+
no-repeat left bottom/ 2px 5px;
161+
box-shadow: inset -4px -4px 0 -2px;
162+
bottom: -6px;
163+
right: -6px;
164+
width: 14px;
165+
height: 18px
166+
}
167+
168+
.gg-copy::after {
169+
width: 6px;
170+
height: 2px;
171+
background: currentColor;
172+
left: 2px;
173+
top: 2px;
174+
box-shadow: 0 4px 0,0 8px 0
175+
}

Assets/WebGLTemplates/Develop/debug-console.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,31 @@ function initialzeDebugConsole() {
55
document.body.appendChild(consoleDiv);
66

77
divLog = (message, className) => {
8-
var entry = document.createElement('p');
9-
entry.className = className;
10-
entry.innerHTML = message;
8+
var entry = document.createElement('div');
9+
entry.classList.add('entry', className);
1110
consoleDiv.appendChild(entry);
1211
consoleDiv.scrollTop = consoleDiv.scrollHeight;
12+
13+
var text = document.createElement('p');
14+
text.innerHTML = message;
15+
entry.appendChild(text);
16+
17+
var copyButton = document.createElement('button');
18+
copyButton.className = 'copy-button';
19+
copyButton.title = 'copy to clipboard';
20+
entry.appendChild(copyButton);
21+
22+
var copyIcon = document.createElement('div');
23+
copyIcon.classList.add('icon', 'gg-copy');
24+
copyButton.appendChild(copyIcon);
25+
copyButton.addEventListener('click', function () {
26+
navigator.clipboard.writeText(message);
27+
28+
copyButton.classList.add('active');
29+
setTimeout(function () {
30+
copyButton.classList.remove('active');
31+
}, 1500);
32+
});
1333
};
1434

1535
defaultConsoleLog = console.log;

0 commit comments

Comments
 (0)