Skip to content

Commit af44a9a

Browse files
committed
www: Implement copy button for rustup download command
1 parent 69453d5 commit af44a9a

File tree

3 files changed

+72
-6
lines changed

3 files changed

+72
-6
lines changed

www/index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,17 @@
2525

2626
<div id="platform-instructions-unix" class="instructions display-none">
2727
<p>Run the following in your terminal, then follow the onscreen instructions.</p>
28-
<pre>curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh</pre>
28+
<div class="copy-container">
29+
<pre>curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh</pre>
30+
<button class="copy-button" title="Copy curl command to clipboard to download Rustup" type="button" onclick="handle_copy_button_click()">
31+
<div class="copy-icon">
32+
<svg width="24" height="25" viewBox="0 0 24 25" xmlns="http://www.w3.org/2000/svg" alt="Copy curl command to clipboard to download Rustup">
33+
<path d="M18 20h2v3c0 1-1 2-2 2H2c-.998 0-2-1-2-2V5c0-.911.755-1.667 1.667-1.667h5A3.323 3.323 0 0110 0a3.323 3.323 0 013.333 3.333h5C19.245 3.333 20 4.09 20 5v8.333h-2V9H2v14h16v-3zM3 7h14c0-.911-.793-1.667-1.75-1.667H13.5c-.957 0-1.75-.755-1.75-1.666C11.75 2.755 10.957 2 10 2s-1.75.755-1.75 1.667c0 .911-.793 1.666-1.75 1.666H4.75C3.793 5.333 3 6.09 3 7z"></path><path d="M4 19h6v2H4zM12 11H4v2h8zM4 17h4v-2H4zM15 15v-3l-4.5 4.5L15 21v-3l8.027-.032L23 15z"></path>
34+
</svg>
35+
</div>
36+
<div id="copy-status-message" class="copy-button-text"></div>
37+
</button>
38+
</div>
2939
<p class="other-platforms-help">You appear to be running Unix. If not, <a class="default-platform-button" href="#">display all supported installers</a>.</p>
3040
</div>
3141

www/rustup.css

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ hr {
105105
margin-bottom: 2em;
106106
}
107107

108-
#platform-instructions-unix > pre,
109-
#platform-instructions-win32 > pre,
110-
#platform-instructions-win64 > pre,
111-
#platform-instructions-default > div > pre,
112-
#platform-instructions-unknown > div > pre {
108+
#platform-instructions-unix > div > pre,
109+
#platform-instructions-win32 > div > pre,
110+
#platform-instructions-win64 > div > pre,
111+
#platform-instructions-default > div > div > pre,
112+
#platform-instructions-unknown > div > div > pre {
113113
background-color: #515151;
114114
color: white;
115115
margin-left: auto;
@@ -121,6 +121,46 @@ hr {
121121
box-shadow: inset 0px 0px 20px 0px #333333;
122122
overflow-x: scroll;
123123
font-size: 0.6em;
124+
height: 27px;
125+
}
126+
127+
#platform-instructions-unix div.copy-container,
128+
#platform-instructions-win32 div.copy-container,
129+
#platform-instructions-win64 div.copy-container,
130+
#platform-instructions-default div.copy-container,
131+
#platform-instructions-unknown div.copy-container {
132+
display: flex;
133+
align-items: center;
134+
}
135+
136+
#platform-instructions-unix button.copy-button,
137+
#platform-instructions-win32 button.copy-button,
138+
#platform-instructions-win64 button.copy-button,
139+
#platform-instructions-default button.copy-button,
140+
#platform-instructions-unknown button.copy-button {
141+
height: 60px;
142+
margin: 1px;
143+
padding-right: 5px;
144+
border-radius: 3px;
145+
}
146+
147+
#platform-instructions-unix div.copy-icon,
148+
#platform-instructions-win32 div.copy-icon,
149+
#platform-instructions-win64 div.copy-icon,
150+
#platform-instructions-default div.copy-icon,
151+
#platform-instructions-unknown div.copy-icon {
152+
margin-top: 12px;
153+
}
154+
155+
#platform-instructions-unix div.copy-button-text,
156+
#platform-instructions-win32 div.copy-button-text,
157+
#platform-instructions-win64 div.copy-button-text,
158+
#platform-instructions-default div.copy-button-text,
159+
#platform-instructions-unknown div.copy-button-text {
160+
font-size: 10px;
161+
color: green;
162+
width: 41px;
163+
height: 15px;
124164
}
125165

126166
#platform-instructions-win32 a.windows-download,

www/rustup.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var platforms = ["default", "unknown", "win32", "win64", "unix"];
44
var platform_override = null;
5+
var rustup_install_command = "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh";
56

67
function detect_platform() {
78
"use strict";
@@ -164,6 +165,21 @@ function fill_in_bug_report_values() {
164165
nav_app.textContent = navigator.appVersion;
165166
}
166167

168+
function clear_copy_status_message() {
169+
document.getElementById('copy-status-message').innerText = '';
170+
}
171+
172+
function handle_copy_button_click() {
173+
try {
174+
navigator.clipboard.writeText(rustup_install_command).then(function() {
175+
document.getElementById('copy-status-message').innerText = 'Copied!'
176+
});
177+
setTimeout(clear_copy_status_message, 5000);
178+
} catch (e) {
179+
console.log('Hit a snag when copying to clipboard:', e);
180+
}
181+
}
182+
167183
(function () {
168184
adjust_for_platform();
169185
set_up_cycle_button();

0 commit comments

Comments
 (0)