{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "terminal",
  "title": "Terminal",
  "author": "VenusUI",
  "description": "A terminal window that types commands and prints their output when it scrolls into view.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/terminal.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { RotateCcw } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst REDUCED_MOTION = \"(prefers-reduced-motion: reduce)\"\n\ninterface TerminalLine {\n  /** `command` lines are typed out after a `$`; the others appear at once. */\n  type: \"command\" | \"output\" | \"success\"\n  text: string\n  /** Milliseconds to wait before this line starts. */\n  delay?: number\n}\n\ninterface TerminalProps {\n  lines: TerminalLine[]\n  /** Title in the window bar. */\n  title?: string\n  /** Milliseconds per typed character. */\n  typingSpeed?: number\n  className?: string\n}\n\n/**\n * A terminal window that types out commands and prints their output once it\n * scrolls into view, then offers a replay button. Screen readers get the\n * whole session as text right away; with reduced motion the finished session\n * shows immediately.\n */\nfunction Terminal({ lines, title = \"Terminal\", typingSpeed = 30, className }: TerminalProps) {\n  const ref = React.useRef<HTMLDivElement>(null)\n  const reduceMotion = React.useSyncExternalStore(\n    (onChange) => {\n      const media = window.matchMedia(REDUCED_MOTION)\n      media.addEventListener(\"change\", onChange)\n      return () => media.removeEventListener(\"change\", onChange)\n    },\n    () => window.matchMedia(REDUCED_MOTION).matches,\n    () => false\n  )\n  const [started, setStarted] = React.useState(false)\n  const [run, setRun] = React.useState(0)\n  // Progress: the index of the line being shown, and how many of its characters.\n  const [progress, setProgress] = React.useState({ line: 0, chars: 0 })\n\n  React.useEffect(() => {\n    const node = ref.current\n    if (!node) return\n    const observer = new IntersectionObserver(\n      ([entry]) => {\n        if (entry?.isIntersecting) {\n          setStarted(true)\n          observer.disconnect()\n        }\n      },\n      { threshold: 0.5 }\n    )\n    observer.observe(node)\n    return () => observer.disconnect()\n  }, [])\n\n  React.useEffect(() => {\n    if (!started || reduceMotion) return\n    const timers: ReturnType<typeof setTimeout>[] = []\n    let at = 300\n    lines.forEach((line, index) => {\n      at += line.delay ?? (line.type === \"command\" ? 400 : 250)\n      if (line.type === \"command\") {\n        for (let c = 0; c <= line.text.length; c++) {\n          const time = at + c * typingSpeed\n          timers.push(setTimeout(() => setProgress({ line: index, chars: c }), time))\n        }\n        at += line.text.length * typingSpeed\n      } else {\n        timers.push(setTimeout(() => setProgress({ line: index, chars: line.text.length }), at))\n      }\n    })\n    timers.push(setTimeout(() => setProgress({ line: lines.length, chars: 0 }), at + 50))\n    return () => timers.forEach(clearTimeout)\n  }, [started, reduceMotion, lines, typingSpeed, run])\n\n  const shown = reduceMotion ? { line: lines.length, chars: 0 } : progress\n  const finished = shown.line >= lines.length\n\n  const replay = () => {\n    setProgress({ line: 0, chars: 0 })\n    setRun((r) => r + 1)\n  }\n\n  const transcript = lines.map((line) => (line.type === \"command\" ? `$ ${line.text}` : line.type === \"success\" ? `✔ ${line.text}` : line.text)).join(\"\\n\")\n\n  return (\n    <div ref={ref} data-slot=\"terminal\" className={cn(\"min-w-0 overflow-hidden rounded-xl border bg-card shadow-sm\", className)}>\n      <div className=\"flex items-center gap-2 border-b px-4 py-2.5\">\n        <span aria-hidden=\"true\" className=\"size-2.5 rounded-full bg-foreground/15\" />\n        <span aria-hidden=\"true\" className=\"size-2.5 rounded-full bg-foreground/15\" />\n        <span aria-hidden=\"true\" className=\"size-2.5 rounded-full bg-foreground/15\" />\n        <span className=\"ml-2 text-xs text-muted-foreground\">{title}</span>\n        {!reduceMotion && finished && started ? (\n          <button\n            type=\"button\"\n            onClick={replay}\n            className=\"ml-auto inline-flex size-7 items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50\"\n          >\n            <RotateCcw aria-hidden=\"true\" className=\"size-3.5\" />\n            <span className=\"sr-only\">Replay</span>\n          </button>\n        ) : null}\n      </div>\n      <pre className=\"sr-only\">{transcript}</pre>\n      <pre aria-hidden=\"true\" className=\"min-h-40 overflow-x-auto p-4 font-mono text-[13px] leading-6\">\n        <code>\n          {lines.map((line, index) => {\n            if (index > shown.line || (index === shown.line && !finished && line.type !== \"command\" && shown.chars === 0)) return null\n            const text = index < shown.line || finished ? line.text : line.text.slice(0, shown.chars)\n            const typing = index === shown.line && !finished && line.type === \"command\"\n            return (\n              <span key={index} className=\"block\">\n                {line.type === \"command\" ? <span className=\"text-muted-foreground select-none\">$ </span> : null}\n                {line.type === \"success\" ? <span className=\"text-emerald-600 dark:text-emerald-400\">✔ </span> : null}\n                <span className={line.type === \"output\" ? \"text-muted-foreground\" : undefined}>{text}</span>\n                {typing ? <span className=\"ml-px inline-block h-4 w-2 translate-y-0.5 animate-pulse bg-foreground/70\" /> : null}\n              </span>\n            )\n          })}\n        </code>\n      </pre>\n    </div>\n  )\n}\n\nexport { Terminal, type TerminalLine, type TerminalProps }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "data-display",
    "text",
    "animations"
  ],
  "type": "registry:ui"
}