Terminal
A terminal session: what was typed, what came back, and errors in their own colour, with an icon and in words.
import { Terminal, TerminalSkeleton } from '@sypnia/ui/react'
A session
Commands, answers and an error. Copy takes the two commands.
sypnia deploy --project storefront
Building… done in 4.2 s
Uploading 12 files (1.4 MB)
The region sa-west-1 does not exist. Use sa-east-1.
sypnia deploy --project storefront --region sa-east-1
Live at https://storefront.sypnia.app
Code
import { Terminal } from '@sypnia/ui/react';
// What was typed, what came back, and what went wrong, each in its own colour and the error with its icon.
// Copy takes only the commands.
export default function Session() {
return (
<Terminal title="deploy" lines={[
{ kind: 'in', text: 'sypnia deploy --project storefront' },
{ text: 'Building… done in 4.2 s' },
{ text: 'Uploading 12 files (1.4 MB)' },
{ kind: 'err', text: 'The region sa-west-1 does not exist. Use sa-east-1.' },
{ kind: 'in', text: 'sypnia deploy --project storefront --region sa-east-1' },
{ text: 'Live at https://storefront.sypnia.app' },
]} />
);
} A command that runs
Press «Run»: a line of skeleton waits for the answer. No spinner.
sypnia db migrate
Code
import { useState } from 'react';
import { Button, Terminal, type TerminalLine } from '@sypnia/ui/react';
// While a command runs, a line of skeleton waits for its answer. Press «Run».
export default function Running() {
const [lines, setLines] = useState<TerminalLine[]>([{ kind: 'in', text: 'sypnia db migrate' }]);
const [busy, setBusy] = useState(false);
const run = () => { setBusy(true); setLines([{ kind: 'in', text: 'sypnia db migrate' }]); setTimeout(() => { setLines((l) => [...l, { text: '3 migrations applied' }]); setBusy(false); }, 1800); };
return (
<div className="sy-stack">
<Terminal title="migrations" lines={lines} loading={busy} />
<div><Button onClick={run} busy={busy}>Run</Button></div>
</div>
);
} Skeleton
The real piece and its skeleton: the same box, so nothing moves when the data arrives.
sypnia logs --tail
12:04:31 GET /orders 200 84 ms
Code
import { Terminal, TerminalSkeleton } from '@sypnia/ui/react';
// A session that is still loading, beside a real one.
export default function Skeleton() {
return (
<div className="sy-stack">
<Terminal title="logs" lines={[{ kind: 'in', text: 'sypnia logs --tail' }, { text: '12:04:31 GET /orders 200 84 ms' }]} />
<TerminalSkeleton lines={2} />
</div>
);
} When to use it
Use it when
- Showing the steps of a command line and their answers.
- A command that is running:
loadingadds a line of skeleton for the answer.
Do not use it when
- The person must copy one command: Snippet.
- It is a long stream of lines to search: LogViewer.
For everyone
- Errors carry an icon and their own words, never only a colour.
- Copy takes only the commands, without the prompt or the answers.
Props
| Terminal | Type | Default |
|---|---|---|
linesrequired | TerminalLine[] | |
loading | boolean | |
prompt | string | $ |
title | string |
| TerminalSkeleton | Type | Default |
|---|---|---|
lines | number | 4 |