- Accordion
- Attachment
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Card
- Checkbox
- Code Block
- Collapsible
- Dialog
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Label
- Marker
- Message
- Number Flow
- Pagination
- Popover
- Progress
- Radio Group
- Select
- Slider
- Sonner
- Spinner
- Switch
- Tooltip
- Separator
- Sheet
- Tabs
- Textarea
- Toggle
- Toggle Group
- Trace
> acme-chat@0.1.0 lint
> eslint .> acme-chat@0.1.0 test
> vitest run
✓ lib/ai.test.ts (6 tests) 41ms
✓ components/chat.test.tsx (9 tests) 212ms
Test Files 2 passed (2)
Tests 15 passed (15)> acme-chat@0.1.0 build
> next build
▲ Next.js 16.3.0
Creating an optimized production build ...
✓ Compiled successfully in 4.2s
✓ Generating static pages (12/12)
Route (app) Size First Load JS
┌ ○ / 1.9 kB 112 kB
└ ƒ /api/chat 141 B 102 kBLint and tests pass, and the build compiled both routes.
Terminal renders a list of shell commands as collapsible trace rows. Each command streams character by character, output appears line by line, and a spinner flips to a checkmark when the command finishes.
Built on top of Trace and Code Block, so the visual language stays consistent with the rest of the registry.
Installation
$ bunx --bun frakment add trace code-block spinner$ npx frakment add trace code-block spinner$ pnpm dlx frakment add trace code-block spinner$ yarn dlx frakment add trace code-block spinner
Install the following dependencies:
$ bun add lucide-react motion$ npm install lucide-react motion$ pnpm add lucide-react motion$ yarn add lucide-react motion
Install the required registry components first:
$ bunx --bun frakment add trace code-block spinner$ npx frakment add trace code-block spinner$ pnpm dlx frakment add trace code-block spinner$ yarn dlx frakment add trace code-block spinner
Copy and paste the following code into your project.
"use client";
import { CheckIcon, TerminalIcon } from "lucide-react";
import { useEffect, useState } from "react";
import { CodeBlock, CodeBlockContent } from "@/components/ui/code-block";
import { Spinner } from "@/components/ui/spinner";
import {
Trace,
TraceCollapsible,
TraceCollapsibleContent,
TraceCollapsibleTrigger,
TraceIcon,
TraceLine,
TraceTitle,
} from "@/components/ui/trace";
import { cn } from "@/lib/utils";
function Terminal({ className, ...props }: React.ComponentProps<"div">) {
return <Trace className={cn("w-full", className)} {...props} />;
}
function TerminalCommand({
command,
output,
status = "done",
defaultOpen = true,
typewriter = true,
typeSpeed = 24,
}: {
command: string;
output: string;
status?: "running" | "done" | "error";
defaultOpen?: boolean;
typewriter?: boolean;
typeSpeed?: number;
}) {
const [open, setOpen] = useState(defaultOpen);
const [visibleChars, setVisibleChars] = useState(
typewriter ? 0 : command.length
);
useEffect(() => {
if (!typewriter) {
setVisibleChars(command.length);
return;
}
setVisibleChars(0);
let c = 0;
const id = setInterval(() => {
c++;
setVisibleChars(c);
if (c >= command.length) {
clearInterval(id);
}
}, typeSpeed);
return () => clearInterval(id);
}, [command, typewriter, typeSpeed]);
const running = status === "running";
const failed = status === "error";
return (
<TraceCollapsible onOpenChange={setOpen} open={open}>
<TraceCollapsibleTrigger>
<TraceLine status={running ? "running" : failed ? "error" : undefined}>
<TraceIcon>
{running ? <Spinner /> : failed ? <TerminalIcon /> : <CheckIcon />}
</TraceIcon>
<TraceTitle>
<span className="text-muted-foreground">$</span>{" "}
{command.slice(0, visibleChars)}
</TraceTitle>
</TraceLine>
</TraceCollapsibleTrigger>
<TraceCollapsibleContent>
<CodeBlock size="sm">
<CodeBlockContent className="max-h-64 whitespace-pre-wrap">
{output || " "}
</CodeBlockContent>
</CodeBlock>
</TraceCollapsibleContent>
</TraceCollapsible>
);
}
export { Terminal, TerminalCommand };Update the import paths to match your project setup.
Usage
import { Terminal, TerminalCommand } from "@/components/ui/terminal";<Terminal>
<TerminalCommand command="npm run build" output="✓ compiled successfully" />
</Terminal>Anatomy
A terminal has three visible parts.
- Trace list — the outer
Tracecontainer, one row per command - Trigger row — icon, spinner or checkmark, and the command text
- Output panel — collapsible
CodeBlockthat streams stdout
Examples
Error output
Mark a TraceLine with status="error" to turn the title red. The collapsible body still uses CodeBlock — anything that fits inside a TraceCollapsibleContent works.
> acme-chat@0.1.0 lint
> eslint .
app/api/chat/route.ts
14:7 error 'model' is assigned a value but never used no-unused-vars
components/chat.tsx
42:5 error React Hook useEffect has a missing dependency: 'messages' react-hooks/exhaustive-deps
✖ 2 problems (2 errors, 0 warnings)
ELIFECYCLE Command failed with exit code 1.Full demo
The preview on this page shows the terminal primitive composing with useChat, createChat, and transport from @frakment/ai. It streams three commands and uses TraceCollapsible for auto-expand during streaming and manual toggle afterwards.
The composition pulls @ai-sdk/react, ai, and every UI primitive it uses. Follow the Chat tutorial for the wiring pattern, or replace createChat with your own backend that streams data-terminal parts.
In Context
Build output
> acme-chat@0.1.0 lint
> eslint .> acme-chat@0.1.0 test
> vitest run
✓ lib/ai.test.ts (6 tests) 41ms
✓ components/chat.test.tsx (9 tests) 212ms
Test Files 2 passed (2)
Tests 15 passed (15)> acme-chat@0.1.0 build
> next build
▲ Next.js 16.3.0
Creating an optimized production build ...
✓ Compiled successfully in 4.2s
✓ Generating static pages (12/12)
Route (app) Size First Load JS
┌ ○ / 1.9 kB 112 kB
└ ƒ /api/chat 141 B 102 kBLint and tests pass, and the build compiled both routes.
Failed command
> acme-chat@0.1.0 lint
> eslint .
app/api/chat/route.ts
14:7 error 'model' is assigned a value but never used no-unused-vars
components/chat.tsx
42:5 error React Hook useEffect has a missing dependency: 'messages' react-hooks/exhaustive-deps
✖ 2 problems (2 errors, 0 warnings)
ELIFECYCLE Command failed with exit code 1.API Reference
TerminalCommand
| Prop | Type | Default | Description |
|---|---|---|---|
command* | string | — | The shell command to display. |
output* | string | — | Combined stdout as a newline-joined string. |
status | "running""done""error" | "done" | Controls the trigger icon. Running shows a spinner, done shows a checkmark, error shows a destructive icon. |
defaultOpen | boolean | true | Whether the output panel is expanded on mount. |
typewriter | boolean | true | Stream the command text character by character. |
typeSpeed | number | 24 | Milliseconds between characters when typing. |
Terminal
Extends React.ComponentProps<"div">. Renders as a Trace container. No custom props — pass TerminalCommand children.
Accessibility
- The trigger uses
CollapsibleTrigger, so keyboard navigation works withTabandEnter/Space. - The trigger row exposes the command text as its accessible label.
- Icons are decorative and inherit
aria-hiddenfrom lucide defaults. - Output renders inside a focusable
<pre>— screen readers can select and copy stdout.
Best Practices
- Collapse by default. Open the terminal only while a command is streaming.
- Cap the output height.
max-h-64onCodeBlockContentscrolls long logs. - Label the command, not the exit. "Ran pnpm build", not "Command complete".
- Do not embed a live terminal. This primitive renders scripted output; for interactive shells, link out.