{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "terminal",
  "title": "Terminal",
  "description": "A macOS-style terminal window that types out a scripted sequence of commands, outputs and comments, with a blinking cursor, auto-scroll and optional looping or manual replay.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/terminal/terminal.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type TerminalSize = \"sm\" | \"md\" | \"lg\";\nexport type TerminalLineType = \"command\" | \"output\" | \"comment\";\n\nexport interface TerminalLine {\n  id: string;\n  type: TerminalLineType;\n  text: string;\n  /** ms per character while typing this line; only used for \"command\" lines. */\n  typingSpeed?: number;\n  /** Extra pause after this line finishes, before the next one starts. */\n  pauseAfter?: number;\n}\n\nexport interface TerminalProps {\n  lines: TerminalLine[];\n  title?: string;\n  prompt?: string;\n  autoPlay?: boolean;\n  loop?: boolean;\n  typingSpeed?: number;\n  lineDelay?: number;\n  startDelay?: number;\n  showControls?: boolean;\n  size?: TerminalSize;\n  theme?: \"dark\" | \"light\";\n  accentColor?: string;\n  width?: number | string;\n  height?: number | string;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0B0B0B\", headerBg: \"#161616\", border: \"rgba(255,255,255,0.1)\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.45)\", prompt: \"#87FFE3\", titleText: \"rgba(245,244,241,0.5)\", hover: \"rgba(255,255,255,0.08)\" },\n  light: { bg: \"#FCFCFC\", headerBg: \"#EFEFEF\", border: \"rgba(10,10,10,0.1)\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.45)\", prompt: \"#0F9F7F\", titleText: \"rgba(10,10,10,0.5)\", hover: \"rgba(10,10,10,0.06)\" },\n};\n\nconst SIZES: Record<TerminalSize, { font: number; lineH: number; pad: number; headerH: number }> = {\n  sm: { font: 12, lineH: 20, pad: 14, headerH: 34 },\n  md: { font: 13, lineH: 22, pad: 18, headerH: 38 },\n  lg: { font: 14.5, lineH: 24, pad: 22, headerH: 42 },\n};\n\ntype Palette = (typeof PALETTES)[\"dark\"];\n\ninterface DisplayLine {\n  line: TerminalLine;\n  text: string;\n  active: boolean;\n}\n\nfunction ReplayIcon({ size }: { size: number }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M13 8a5 5 0 1 1-1.7-3.75\" />\n      <path d=\"M13 2.5V5h-2.5\" />\n    </svg>\n  );\n}\n\nfunction Row({ item, prompt, p }: { item: DisplayLine; prompt: string; p: Palette }) {\n  const { line, text, active } = item;\n  if (line.type === \"output\") {\n    return (\n      <div style={{ color: p.text, opacity: 0.85, whiteSpace: \"pre-wrap\" }}>\n        {text}\n        {text.length === 0 && \" \"}\n      </div>\n    );\n  }\n  if (line.type === \"comment\") {\n    return (\n      <div style={{ color: p.muted, fontStyle: \"italic\" }}>\n        {\"# \"}\n        {text}\n      </div>\n    );\n  }\n  return (\n    <div className=\"flex\" style={{ gap: 8 }}>\n      <span className=\"shrink-0 font-semibold\" style={{ color: p.prompt }}>\n        {prompt}\n      </span>\n      <span style={{ color: p.text, whiteSpace: \"pre-wrap\", wordBreak: \"break-word\" }}>\n        {text}\n        {active && (\n          <motion.span\n            aria-hidden=\"true\"\n            className=\"inline-block align-middle\"\n            style={{ width: \"0.55em\", height: \"1.05em\", marginLeft: 1, background: p.text, verticalAlign: \"-0.15em\" }}\n            animate={{ opacity: [1, 1, 0, 0] }}\n            transition={{ duration: 1, repeat: Infinity, times: [0, 0.5, 0.5, 1] }}\n          />\n        )}\n      </span>\n    </div>\n  );\n}\n\nexport function Terminal({\n  lines,\n  title = \"zsh\",\n  prompt = \"$\",\n  autoPlay = true,\n  loop = true,\n  typingSpeed = 32,\n  lineDelay = 400,\n  startDelay = 500,\n  showControls = true,\n  size = \"md\",\n  theme = \"dark\",\n  accentColor,\n  width,\n  height = 280,\n  className,\n}: TerminalProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const [displayed, setDisplayed] = React.useState<DisplayLine[]>([]);\n  const [finished, setFinished] = React.useState(false);\n  const genRef = React.useRef(0);\n  const timers = React.useRef<ReturnType<typeof setTimeout>[]>([]);\n  const bodyRef = React.useRef<HTMLDivElement>(null);\n\n  const schedule = React.useCallback((fn: () => void, delay: number) => {\n    const t = setTimeout(fn, Math.max(0, delay));\n    timers.current.push(t);\n    return t;\n  }, []);\n\n  const clearTimers = React.useCallback(() => {\n    timers.current.forEach(clearTimeout);\n    timers.current = [];\n  }, []);\n\n  // Looping calls back into `play` from deep inside its own timer chain,\n  // before the const finishes initializing — going through a ref (resolved\n  // when the timer actually fires, not when `play` is defined) sidesteps\n  // that self-reference instead of relying on closure-capturing a\n  // not-yet-assigned binding.\n  const playRef = React.useRef<(gen: number) => void>(() => {});\n\n  const play = React.useCallback(\n    (gen: number) => {\n      setDisplayed([]);\n      setFinished(false);\n      let li = 0;\n\n      const startLine = () => {\n        if (gen !== genRef.current) return;\n        if (li >= lines.length) {\n          setFinished(true);\n          setDisplayed((prev) => prev.map((d, i) => (i === prev.length - 1 ? { ...d, active: false } : d)));\n          if (loop) schedule(() => playRef.current(gen), 1400);\n          return;\n        }\n        const line = lines[li];\n        setDisplayed((prev) => [...prev, { line, text: \"\", active: line.type === \"command\" }]);\n\n        if (line.type === \"command\") {\n          let ci = 0;\n          const typeChar = () => {\n            if (gen !== genRef.current) return;\n            ci++;\n            setDisplayed((prev) => prev.map((d, i) => (i === prev.length - 1 ? { ...d, text: line.text.slice(0, ci) } : d)));\n            if (ci < line.text.length) {\n              schedule(typeChar, line.typingSpeed ?? typingSpeed);\n            } else {\n              setDisplayed((prev) => prev.map((d, i) => (i === prev.length - 1 ? { ...d, active: false } : d)));\n              li++;\n              schedule(startLine, line.pauseAfter ?? lineDelay);\n            }\n          };\n          schedule(typeChar, line.typingSpeed ?? typingSpeed);\n        } else {\n          setDisplayed((prev) => prev.map((d, i) => (i === prev.length - 1 ? { ...d, text: line.text } : d)));\n          li++;\n          schedule(startLine, line.pauseAfter ?? lineDelay * 0.6);\n        }\n      };\n\n      schedule(startLine, startDelay);\n    },\n    [lines, loop, typingSpeed, lineDelay, startDelay, schedule],\n  );\n  React.useEffect(() => {\n    playRef.current = play;\n  }, [play]);\n\n  React.useEffect(() => {\n    if (!autoPlay) return;\n    genRef.current++;\n    const gen = genRef.current;\n    play(gen);\n    return () => {\n      genRef.current = gen + 1;\n      clearTimers();\n    };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [lines, autoPlay, loop]);\n\n  React.useEffect(() => {\n    const el = bodyRef.current;\n    if (el) el.scrollTop = el.scrollHeight;\n  }, [displayed]);\n\n  const replay = () => {\n    genRef.current++;\n    clearTimers();\n    play(genRef.current);\n  };\n\n  return (\n    <div\n      className={cn(\"flex flex-col overflow-hidden\", className)}\n      style={{ width, maxWidth: \"100%\", height, borderRadius: 14, background: p.bg, border: `1px solid ${p.border}`, fontFamily: \"Inter, sans-serif\", boxShadow: \"0 24px 60px rgba(0,0,0,0.35)\" }}\n    >\n      <div className=\"relative flex shrink-0 items-center justify-center\" style={{ height: s.headerH, padding: `0 ${s.pad}px`, background: p.headerBg, borderBottom: `1px solid ${p.border}` }}>\n        {showControls && (\n          <div className=\"absolute flex items-center\" style={{ left: s.pad, gap: 7 }}>\n            <span className=\"rounded-full\" style={{ width: 11, height: 11, background: \"#FF5F57\" }} />\n            <span className=\"rounded-full\" style={{ width: 11, height: 11, background: \"#FEBC2E\" }} />\n            <span className=\"rounded-full\" style={{ width: 11, height: 11, background: \"#28C840\" }} />\n          </div>\n        )}\n        <span className=\"truncate font-medium\" style={{ color: p.titleText, fontSize: s.font - 1 }}>\n          {title}\n        </span>\n        {!loop && finished && (\n          <button\n            type=\"button\"\n            onClick={replay}\n            aria-label=\"Replay\"\n            className=\"absolute flex cursor-pointer items-center justify-center rounded-md border-none bg-transparent outline-none focus-visible:ring-2\"\n            style={{ right: s.pad - 6, width: 24, height: 24, color: p.titleText, [\"--tw-ring-color\" as string]: accentColor ?? p.text }}\n            onMouseEnter={(e) => (e.currentTarget.style.background = p.hover)}\n            onMouseLeave={(e) => (e.currentTarget.style.background = \"transparent\")}\n          >\n            <ReplayIcon size={s.font} />\n          </button>\n        )}\n      </div>\n\n      <div ref={bodyRef} className=\"min-h-0 flex-1 overflow-auto\" style={{ padding: s.pad, fontFamily: \"ui-monospace, SFMono-Regular, Menlo, monospace\" }}>\n        <div className=\"flex flex-col\" style={{ gap: s.lineH * 0.18, fontSize: s.font, lineHeight: `${s.lineH}px` }}>\n          {displayed.map((item, i) => (\n            <Row key={`${item.line.id}-${i}`} item={item} prompt={prompt} p={p} />\n          ))}\n        </div>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}