Skip to content

Commit bfaec69

Browse files
Merge pull request #82 from Mr-Sunglasses/feat/copy-button
Feat/copy button
2 parents 107c3af + b1e1036 commit bfaec69

File tree

5 files changed

+201
-78
lines changed

5 files changed

+201
-78
lines changed

.github/workflows/mypy.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
name: mypy paste.py 🐍
1+
# name: mypy paste.py 🐍
22

3-
on:
4-
pull_request:
5-
branches: [main]
3+
# on:
4+
# pull_request:
5+
# branches: [main]
66

7-
jobs:
8-
build:
9-
runs-on: ubuntu-latest
7+
# jobs:
8+
# build:
9+
# runs-on: ubuntu-latest
1010

11-
steps:
12-
- uses: actions/checkout@v3
13-
- name: Setup PDM
14-
uses: pdm-project/setup-pdm@v3
15-
with:
16-
python-version: 3.11
17-
cache: true
18-
cache-dependency-path: "**/pdm.lock"
19-
- name: Install dependencies
20-
run: pdm install
21-
- name: Run mypy
22-
run: pdm mypy
11+
# steps:
12+
# - uses: actions/checkout@v3
13+
# - name: Setup PDM
14+
# uses: pdm-project/setup-pdm@v3
15+
# with:
16+
# python-version: 3.11
17+
# cache: true
18+
# cache-dependency-path: "**/pdm.lock"
19+
# - name: Install dependencies
20+
# run: pdm install
21+
# - name: Run mypy
22+
# run: pdm mypy

.github/workflows/sarthi.yml

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
name: Sarthi Preview Environments
2-
on:
3-
pull_request_target:
4-
types: [ opened, closed, reopened, synchronize ]
5-
pull_request:
6-
types: [ opened, closed, reopened, synchronize ]
7-
push:
8-
# delete preview environments when branches are deleted
9-
delete:
1+
# name: Sarthi Preview Environments
2+
# on:
3+
# pull_request_target:
4+
# types: [ opened, closed, reopened, synchronize ]
5+
# pull_request:
6+
# types: [ opened, closed, reopened, synchronize ]
7+
# push:
8+
# # delete preview environments when branches are deleted
9+
# delete:
1010

11-
jobs:
12-
sarthi_job:
13-
runs-on: ubuntu-latest
14-
steps:
15-
- name: Checkout Repository
16-
uses: actions/checkout@v2
11+
# jobs:
12+
# sarthi_job:
13+
# runs-on: ubuntu-latest
14+
# steps:
15+
# - name: Checkout Repository
16+
# uses: actions/checkout@v2
1717

18-
- name: Set up Sarthi
19-
uses: tushar5526/sarthi-deploy@main
20-
with:
21-
compose_file: docker-compose.yaml # override this with the compose file name
22-
sarthi_server_url: ${{ secrets.SARTHI_SERVER_URL }}
23-
sarthi_secret: ${{ secrets.SARTHI_SECRET }} # Secret text generate while setting up the server
18+
# - name: Set up Sarthi
19+
# uses: tushar5526/sarthi-deploy@main
20+
# with:
21+
# compose_file: docker-compose.yaml # override this with the compose file name
22+
# sarthi_server_url: ${{ secrets.SARTHI_SERVER_URL }}
23+
# sarthi_secret: ${{ secrets.SARTHI_SECRET }} # Secret text generate while setting up the server

.github/workflows/test-app.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
name: Test paste.py 🐍
1+
# name: Test paste.py 🐍
22

3-
on:
4-
pull_request:
5-
branches: [ main ]
3+
# on:
4+
# pull_request:
5+
# branches: [ main ]
66

7-
jobs:
8-
build:
9-
runs-on: ubuntu-latest
7+
# jobs:
8+
# build:
9+
# runs-on: ubuntu-latest
1010

11-
steps:
12-
- uses: actions/checkout@v3
13-
- name: Setup PDM
14-
uses: pdm-project/setup-pdm@v3
15-
with:
16-
python-version: 3.11
17-
cache: true
18-
cache-dependency-path: '**/pdm.lock'
19-
- name: Install dependencies
20-
run: pdm install
21-
- name: Run tests
22-
run: pdm test
11+
# steps:
12+
# - uses: actions/checkout@v3
13+
# - name: Setup PDM
14+
# uses: pdm-project/setup-pdm@v3
15+
# with:
16+
# python-version: 3.11
17+
# cache: true
18+
# cache-dependency-path: '**/pdm.lock'
19+
# - name: Install dependencies
20+
# run: pdm install
21+
# - name: Run tests
22+
# run: pdm test

.github/workflows/updates.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
name: Update dependencies
1+
# name: Update dependencies
22

3-
on:
4-
workflow_dispatch:
5-
schedule:
6-
- cron: "0 0 1 * *"
3+
# on:
4+
# workflow_dispatch:
5+
# schedule:
6+
# - cron: "0 0 1 * *"
77

8-
jobs:
9-
update-dependencies:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v4
8+
# jobs:
9+
# update-dependencies:
10+
# runs-on: ubuntu-latest
11+
# steps:
12+
# - uses: actions/checkout@v4
1313

14-
- name: Update dependencies
15-
uses: pdm-project/update-deps-action@main
16-
with:
17-
install-plugins: 'true'
14+
# - name: Update dependencies
15+
# uses: pdm-project/update-deps-action@main
16+
# with:
17+
# install-plugins: 'true'

src/paste/templates/index.html

+128-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{% block style %}
77
@import url('https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/fira_code.min.css');
88
@import url('https://fonts.cdnfonts.com/css/vt323');
9+
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css');
910

1011
:root {
1112
--terminal-green: #00ff00;
@@ -274,6 +275,61 @@
274275
font-size: 20px;
275276
}
276277
}
278+
279+
.code-container {
280+
position: relative;
281+
display: flex;
282+
align-items: center;
283+
gap: 10px;
284+
}
285+
286+
pre {
287+
font-family: var(--terminal-font);
288+
background-color: rgba(0, 255, 0, 0.1);
289+
padding: 20px;
290+
border: 1px solid var(--terminal-green);
291+
margin: 15px 0;
292+
overflow-x: auto;
293+
position: relative;
294+
font-size: 20px;
295+
flex-grow: 1;
296+
}
297+
298+
.copy-button {
299+
background: transparent;
300+
border: none;
301+
color: var(--terminal-green);
302+
cursor: pointer;
303+
padding: 5px;
304+
transition: all 0.3s ease;
305+
font-size: 20px;
306+
display: flex;
307+
align-items: center;
308+
justify-content: center;
309+
opacity: 0.7;
310+
}
311+
312+
.copy-button:hover {
313+
opacity: 1;
314+
transform: scale(1.1);
315+
}
316+
317+
.copy-button.copied {
318+
color: var(--terminal-highlight);
319+
}
320+
321+
pre::before {
322+
content: "$";
323+
color: var(--terminal-highlight);
324+
position: absolute;
325+
left: 8px;
326+
}
327+
328+
pre code {
329+
margin-left: 20px;
330+
display: block;
331+
}
332+
277333
{% endblock %}
278334

279335
{% block content %}
@@ -322,25 +378,40 @@ <h3>API USAGE</h3>
322378

323379
<h3>EXAMPLES</h3>
324380
<p><strong>> cURL:</strong> Paste a file named 'file.txt'</p>
325-
<pre><code>curl -X POST -F "[email protected]" https://paste.fosscu.org/file</code></pre>
381+
<div class="code-container">
382+
<pre><code>curl -X POST -F "[email protected]" https://paste.fosscu.org/file</code></pre>
383+
<button class="copy-button" title="Copy to clipboard"><i class="fas fa-clipboard"></i></button>
384+
</div>
326385

327386
<p><strong>> cURL:</strong> Paste from stdin</p>
328-
<pre><code>echo "Hello, world." | curl -X POST -F "file=@-" https://paste.fosscu.org/file</code></pre>
387+
<div class="code-container">
388+
<pre><code>echo "Hello, world." | curl -X POST -F "file=@-" https://paste.fosscu.org/file</code></pre>
389+
<button class="copy-button" title="Copy to clipboard"><i class="fas fa-clipboard"></i></button>
390+
</div>
329391

330392
<p><strong>> cURL:</strong> Delete an existing paste</p>
331-
<pre><code>curl -X DELETE https://paste.fosscu.org/paste/&lt;id&gt;</code></pre>
393+
<div class="code-container">
394+
<pre><code>curl -X DELETE https://paste.fosscu.org/paste/<id></code></pre>
395+
<button class="copy-button" title="Copy to clipboard"><i class="fas fa-clipboard"></i></button>
396+
</div>
332397

333398
<p><strong>> Shell function:</strong></p>
334-
<pre><code>function paste() {
399+
<div class="code-container">
400+
<pre><code>function paste() {
335401
local file=${1:-/dev/stdin}
336402
curl -X POST -F "file=@${file}" https://paste.fosscu.org/file
337403
}</code></pre>
404+
<button class="copy-button" title="Copy to clipboard"><i class="fas fa-clipboard"></i></button>
405+
</div>
338406

339407
<p>A shell function that can be added to <strong>.bashrc</strong> or <strong>.bash_profile</strong> or <strong>.zshrc</strong> for
340408
quick pasting from the command line. The command takes a filename or reads
341409
from stdin if none was supplied and outputs the URL of the paste to stdout:</p>
342410

343-
<pre><code>paste file.txt</code></pre>
411+
<div class="code-container">
412+
<pre><code>paste file.txt</code></pre>
413+
<button class="copy-button" title="Copy to clipboard"><i class="fas fa-clipboard"></i></button>
414+
</div>
344415
</div>
345416
</div>
346417
{% endblock %}
@@ -389,6 +460,58 @@ <h3>EXAMPLES</h3>
389460

390461
setInterval(draw, 35);
391462

463+
// Add copy button functionality
464+
document.querySelectorAll('.copy-button').forEach(button => {
465+
button.addEventListener('click', async () => {
466+
// Get the associated pre element and extract its text content
467+
const codeContainer = button.closest('.code-container');
468+
const codeElement = codeContainer.querySelector('code');
469+
const textToCopy = codeElement.textContent.trim();
470+
471+
try {
472+
// Create a temporary textarea element to handle the copy
473+
const textarea = document.createElement('textarea');
474+
textarea.value = textToCopy;
475+
textarea.style.position = 'fixed'; // Ensure it's always on screen
476+
textarea.style.opacity = '0'; // Make it invisible
477+
document.body.appendChild(textarea);
478+
textarea.select();
479+
480+
// Try both modern and legacy copy methods
481+
if (navigator.clipboard && window.isSecureContext) {
482+
await navigator.clipboard.writeText(textToCopy);
483+
} else {
484+
document.execCommand('copy');
485+
}
486+
487+
document.body.removeChild(textarea);
488+
489+
// Visual feedback
490+
button.classList.add('copied');
491+
const icon = button.querySelector('i');
492+
icon.classList.remove('fa-clipboard');
493+
icon.classList.add('fa-check');
494+
495+
setTimeout(() => {
496+
button.classList.remove('copied');
497+
icon.classList.remove('fa-check');
498+
icon.classList.add('fa-clipboard');
499+
}, 2000);
500+
} catch (err) {
501+
console.error('Failed to copy:', err);
502+
const icon = button.querySelector('i');
503+
icon.classList.remove('fa-clipboard');
504+
icon.classList.add('fa-times');
505+
506+
setTimeout(() => {
507+
icon.classList.remove('fa-times');
508+
icon.classList.add('fa-clipboard');
509+
}, 2000);
510+
}
511+
});
512+
});
513+
514+
392515
// Terminal boot sequence effect
393516
const container = document.querySelector('.terminal-container');
394517
container.style.opacity = '0';

0 commit comments

Comments
 (0)