{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "terminal-output-demo",
  "title": "Terminal Output Demo",
  "description": "A worked example of Terminal Output: Streaming command output with stderr called out, an exit code, and scroll that follows without trapping you.",
  "dependencies": [
    "lucide-react@^1.31.0"
  ],
  "registryDependencies": [
    "https://ui.tinkererslabs.com/r/terminal-output.json"
  ],
  "files": [
    {
      "path": "components/demos/terminal-output-demo.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { DemoVariants } from \"@/components/demos/demo-variants\"\nimport { RestartButton } from \"@/components/demos/restart-button\"\nimport {\n  TerminalOutput,\n  type TerminalLine,\n} from \"@/registry/default/terminal-output/terminal-output\"\n\nconst script: TerminalLine[] = [\n  { text: \"Packages: +214\" },\n  { text: \"Progress: resolved 214, reused 210, downloaded 4\" },\n  { text: \"\" },\n  { text: \"dependencies:\" },\n  { text: \"+ mischief-ui 0.7.1\" },\n  { text: \"\" },\n  { text: \"Done in 1.8s\" },\n]\n\nconst failure: TerminalLine[] = [\n  {\n    text: \"src/total.ts(4,17): error TS2554: Expected 1 arguments, but got 2.\",\n    stream: \"stderr\",\n  },\n  { text: \"\", stream: \"stderr\" },\n  { text: \"Found 1 error in src/total.ts\", stream: \"stderr\" },\n]\n\nfunction LiveRun() {\n  const [count, setCount] = React.useState(0)\n  const [runId, setRunId] = React.useState(0)\n\n  React.useEffect(() => {\n    if (count >= script.length) return\n\n    const timer = setTimeout(() => setCount((shown) => shown + 1), 420)\n    return () => clearTimeout(timer)\n  }, [count, runId])\n\n  const done = count >= script.length\n\n  return (\n    <div className=\"grid gap-4\">\n      <TerminalOutput\n        command=\"pnpm install mischief-ui\"\n        cwd=\"~/projects/shop\"\n        output={script.slice(0, count)}\n        running={!done}\n        exitCode={done ? 0 : undefined}\n        maxHeight=\"11rem\"\n      />\n\n      {done ? (\n        <RestartButton\n          onClick={() => {\n            setCount(0)\n            setRunId((id) => id + 1)\n          }}\n        />\n      ) : null}\n    </div>\n  )\n}\n\nexport function TerminalOutputDemo() {\n  return (\n    <DemoVariants\n      label=\"Command run\"\n      variants={[\n        { id: \"live\", label: \"Streaming\", render: () => <LiveRun /> },\n        {\n          id: \"failed\",\n          label: \"Failed\",\n          render: () => (\n            <TerminalOutput\n              command=\"pnpm typecheck\"\n              output={failure}\n              exitCode={2}\n              maxHeight=\"11rem\"\n            />\n          ),\n        },\n      ]}\n    />\n  )\n}\n",
      "type": "registry:example"
    },
    {
      "path": "components/demos/demo-variants.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nexport type DemoVariant = {\n  id: string\n  label: string\n  render: () => React.ReactNode\n}\n\nexport function DemoVariants({\n  variants,\n  label = \"Demo variant\",\n}: {\n  variants: [DemoVariant, ...DemoVariant[]]\n  label?: string\n}) {\n  const [activeId, setActiveId] = React.useState(variants[0].id)\n  const active =\n    variants.find((variant) => variant.id === activeId) ?? variants[0]\n\n  return (\n    <div className=\"grid w-full justify-items-center gap-6\">\n      {/* Centres whatever the variant renders. Without this a demo that caps\n          its own width sits against the left edge while the switch below it\n          is centred, which reads as a mistake. */}\n      <div className=\"flex w-full justify-center\">{active.render()}</div>\n\n      <div\n        role=\"group\"\n        aria-label={label}\n        className=\"border-border bg-background/70 inline-flex flex-wrap justify-center gap-1 rounded-full border p-1\"\n      >\n        {variants.map((variant) => {\n          const isActive = variant.id === active.id\n\n          return (\n            <button\n              key={variant.id}\n              type=\"button\"\n              aria-pressed={isActive}\n              className={\n                isActive\n                  ? \"bg-foreground text-background rounded-full px-3 py-1.5 text-xs font-semibold\"\n                  : \"text-muted-foreground hover:text-foreground rounded-full px-3 py-1.5 text-xs font-semibold\"\n              }\n              onClick={() => setActiveId(variant.id)}\n            >\n              {variant.label}\n            </button>\n          )\n        })}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:example"
    },
    {
      "path": "components/demos/restart-button.tsx",
      "content": "\"use client\"\n\nimport { RotateCcw } from \"lucide-react\"\n\nexport function RestartButton({ onClick }: { onClick: () => void }) {\n  return (\n    <button className=\"restore-button\" type=\"button\" onClick={onClick}>\n      <RotateCcw aria-hidden=\"true\" size={15} /> Replay\n    </button>\n  )\n}\n",
      "type": "registry:example"
    }
  ],
  "type": "registry:example"
}