Terminal
import { useEffect, useRef, useState } from 'react';
const css = `
@keyframes btn-terminal-caret { 50% { opacity: 0; } }
.btn-terminal {
display: inline-flex;
flex-direction: column;
width: 25ch;
padding: 0;
border: 1px solid light-dark(#dbdde1, #2e3035);
border-radius: 10px;
background: light-dark(#fbfcfd, #121417);
color: light-dark(#42454c, #e5e6e9);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 13px;
text-align: left;
cursor: pointer;
overflow: hidden;
transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.btn-terminal:hover { border-color: light-dark(#6d7179, #7d8087); box-shadow: 0 0 22px color-mix(in oklab, light-dark(#373a40, #f1f2f3) 10%, transparent); }
.btn-terminal:focus-visible { outline: 2px solid light-dark(#42454c, #e5e6e9); outline-offset: 3px; }
.btn-terminal__bar {
display: flex;
gap: 5px;
padding: 7px 10px;
border-bottom: 1px solid light-dark(#ebedf0, #232529);
background: light-dark(#f3f4f7, #1a1c1f);
}
.btn-terminal__bar i { width: 7px; height: 7px; border-radius: 50%; background: light-dark(#dbdde1, #2e3035); }
.btn-terminal__body {
display: grid;
gap: 2px;
padding: 10px 12px 12px;
min-height: 3.9em;
white-space: pre;
}
.btn-terminal__prompt { color: light-dark(#6d7179, #7d8087); }
.btn-terminal__cmd { color: light-dark(#373a40, #f1f2f3); }
.btn-terminal__out { color: light-dark(#5f626a, #a7abb2); }
.btn-terminal__out--ok { color: light-dark(#373a40, #f1f2f3); }
.btn-terminal__caret {
display: inline-block;
width: 0.6em;
height: 1.05em;
margin-left: 1px;
vertical-align: -0.15em;
background: light-dark(#373a40, #f1f2f3);
animation: btn-terminal-caret 1s steps(1) infinite;
}
@media (prefers-reduced-motion: reduce) { .btn-terminal__caret { animation: none; } }
`;
const CMD = 'deploy --prod';
const BAR = 12;
export function TerminalButton() {
const [typed, setTyped] = useState(0);
const [progress, setProgress] = useState<number | null>(null);
const [done, setDone] = useState(false);
const busy = useRef(false);
const timers = useRef<number[]>([]);
useEffect(() => () => timers.current.forEach(clearTimeout), []);
const at = (ms: number, fn: () => void) => timers.current.push(window.setTimeout(fn, ms));
const run = () => {
if (busy.current) return;
busy.current = true;
setTyped(0);
setProgress(null);
setDone(false);
let t = 0;
for (let i = 1; i <= CMD.length; i++) at((t += 45), () => setTyped(i));
t += 200;
for (let i = 0; i <= BAR; i++) at((t += 90 + (i % 4 === 0 ? 120 : 0)), () => setProgress(i));
at((t += 250), () => setDone(true));
at((t += 2200), () => {
setProgress(null);
setDone(false);
setTyped(0);
busy.current = false;
});
};
const bar =
progress === null ? null : `[${'#'.repeat(progress)}${'.'.repeat(BAR - progress)}] ${String(Math.round((progress / BAR) * 100)).padStart(3)}%`;
return (
<>
<style>
{css}
</style>
<button type="button" className="btn-terminal" onClick={run} aria-label="Deploy to production">
<span className="btn-terminal__bar" aria-hidden="true">
<i />
<i />
<i />
</span>
<span className="btn-terminal__body" aria-hidden="true">
<span>
<span className="btn-terminal__prompt">~ $ </span>
<span className="btn-terminal__cmd">{busy.current || typed ? CMD.slice(0, typed) : 'deploy'}</span>
{progress === null && !done && <span className="btn-terminal__caret" />}
</span>
{bar && <span className="btn-terminal__out">{bar}</span>}
{done && <span className="btn-terminal__out btn-terminal__out--ok">✓ live in 1.2s</span>}
</span>
<span className="sr-only" aria-live="polite">
{done ? 'Deployed' : ''}
</span>
</button>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initBtnTerminal(el) on the mounted element instead.
<button type="button" class="btn-terminal" aria-label="Deploy to production">
<span class="btn-terminal__bar" aria-hidden="true">
<i></i>
<i></i>
<i></i>
</span>
<span class="btn-terminal__body" aria-hidden="true"><span><span class="btn-terminal__prompt">~ $ </span><span class="btn-terminal__cmd">deploy</span><span class="btn-terminal__caret"></span></span></span>
<span class="btn-terminal__sr" aria-live="polite"></span>
</button>@keyframes btn-terminal-caret { 50% { opacity: 0; } }
.btn-terminal {
display: inline-flex;
flex-direction: column;
width: 25ch;
padding: 0;
border: 1px solid light-dark(#dbdde1, #2e3035);
border-radius: 10px;
background: light-dark(#fbfcfd, #121417);
color: light-dark(#42454c, #e5e6e9);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 13px;
text-align: left;
cursor: pointer;
overflow: hidden;
transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.btn-terminal:hover { border-color: light-dark(#6d7179, #7d8087); box-shadow: 0 0 22px color-mix(in oklab, light-dark(#373a40, #f1f2f3) 10%, transparent); }
.btn-terminal:focus-visible { outline: 2px solid light-dark(#42454c, #e5e6e9); outline-offset: 3px; }
.btn-terminal__bar {
display: flex;
gap: 5px;
padding: 7px 10px;
border-bottom: 1px solid light-dark(#ebedf0, #232529);
background: light-dark(#f3f4f7, #1a1c1f);
}
.btn-terminal__bar i { width: 7px; height: 7px; border-radius: 50%; background: light-dark(#dbdde1, #2e3035); }
.btn-terminal__body {
display: grid;
gap: 2px;
padding: 10px 12px 12px;
min-height: 3.9em;
white-space: pre;
}
.btn-terminal__prompt { color: light-dark(#6d7179, #7d8087); }
.btn-terminal__cmd { color: light-dark(#373a40, #f1f2f3); }
.btn-terminal__out { color: light-dark(#5f626a, #a7abb2); }
.btn-terminal__out--ok { color: light-dark(#373a40, #f1f2f3); }
.btn-terminal__caret {
display: inline-block;
width: 0.6em;
height: 1.05em;
margin-left: 1px;
vertical-align: -0.15em;
background: light-dark(#373a40, #f1f2f3);
animation: btn-terminal-caret 1s steps(1) infinite;
}
@media (prefers-reduced-motion: reduce) { .btn-terminal__caret { animation: none; } }
.btn-terminal__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }function initBtnTerminal(root) {
var body = root.querySelector('.btn-terminal__body');
var cmd = root.querySelector('.btn-terminal__cmd');
var live = root.querySelector('.btn-terminal__sr');
if (!body || !cmd || !live) return;
var CMD = 'deploy --prod';
var BAR = 12;
var caret = root.querySelector('.btn-terminal__caret');
var busy = false;
var timers = [];
var out = null;
function at(ms, fn) { timers.push(setTimeout(fn, ms)); }
function line(cls, s) {
var el = document.createElement('span');
el.className = cls;
el.textContent = s;
body.appendChild(el);
return el;
}
function run() {
if (busy) return;
busy = true;
live.textContent = '';
cmd.textContent = '';
var t = 0;
for (var i = 1; i <= CMD.length; i++) {
(function (n) { at((t += 45), function () { cmd.textContent = CMD.slice(0, n); }); })(i);
}
t += 200;
for (var j = 0; j <= BAR; j++) {
(function (n) {
at((t += 90 + (n % 4 === 0 ? 120 : 0)), function () {
if (caret) caret.remove();
out = out || line('btn-terminal__out', '');
out.textContent = '[' + '#'.repeat(n) + '.'.repeat(BAR - n) + '] ' + String(Math.round((n / BAR) * 100)).padStart(3) + '%';
});
})(j);
}
at((t += 250), function () {
line('btn-terminal__out btn-terminal__out--ok', '✓ live in 1.2s');
live.textContent = 'Deployed';
});
at((t += 2200), function () {
body.querySelectorAll('.btn-terminal__out').forEach(function (el) { el.remove(); });
out = null;
cmd.textContent = 'deploy';
if (caret) cmd.parentNode.appendChild(caret);
live.textContent = '';
busy = false;
});
}
root.addEventListener('click', run);
return function () {
timers.forEach(clearTimeout);
root.removeEventListener('click', run);
};
}
document.querySelectorAll('.btn-terminal').forEach(initBtnTerminal);Goal: Create a "Terminal" button.
Visual behavior: A button that is a tiny terminal window. A click types out the deploy command, runs an ASCII progress bar to 100% in uneven steps, prints a success line, then resets to the prompt.
Technique:
- A window bar with three dots over a monospace body; the prompt shows a blinking block caret (a steps(1) opacity keyframe).
- A click schedules a timeline of timeouts: the command types a character every 45ms, then a [####....] bar fills in twelve steps with a pause every fourth, then a tick line appears.
- A busy flag ignores clicks mid-run; after 2.2s everything clears back to the prompt.
- The visible window is aria-hidden; a visually hidden live region announces "Deployed".
Accessibility: A real <button> named "Deploy to production"; completion is announced through a visually hidden aria-live region. Focus outline. Under prefers-reduced-motion the caret stops blinking.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Terminal" button.
Visual behavior: A button that is a tiny terminal window. A click types out the deploy command, runs an ASCII progress bar to 100% in uneven steps, prints a success line, then resets to the prompt.
Technique:
- A window bar with three dots over a monospace body; the prompt shows a blinking block caret (a steps(1) opacity keyframe).
- A click schedules a timeline of timeouts: the command types a character every 45ms, then a [####....] bar fills in twelve steps with a pause every fourth, then a tick line appears.
- A busy flag ignores clicks mid-run; after 2.2s everything clears back to the prompt.
- The visible window is aria-hidden; a visually hidden live region announces "Deployed".
Accessibility: A real <button> named "Deploy to production"; completion is announced through a visually hidden aria-live region. Focus outline. Under prefers-reduced-motion the caret stops blinking.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
About this component
A button that is a tiny terminal window. A click types out the deploy command, runs an ASCII progress bar to 100% in uneven steps, prints a success line, then resets to the prompt.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- click, state change, continuous
- Techniques
- text animation, state machine, keyframes
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
A real <button> named "Deploy to production"; completion is announced through a visually hidden aria-live region. Focus outline. Under prefers-reduced-motion the caret stops blinking.