{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "terminal",
  "title": "Terminal",
  "description": "A command and its output in ANSI colors, following the end as it streams, with its approval, exit code and duration.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/react@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup",
    "@kind-ui/confirmation"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/react/terminal.tsx",
      "content": "\"use client\";\n\nimport { type AnsiSpan, terminalPrimitive } from \"@kind-ui/agent-ui/core\";\nimport { createParts } from \"@ui-sdk/react/primitive\";\nimport { type ComponentProps, Fragment, memo } from \"react\";\nimport { Confirmation } from \"./confirmation\";\n\nconst parts = createParts(terminalPrimitive, {\n  root: \"div\",\n  trigger: \"button\",\n  icon: \"span\",\n  title: \"span\",\n  exit: \"span\",\n  meta: \"span\",\n  approval: \"div\",\n  content: \"div\",\n  command: \"div\",\n  copy: \"button\",\n  viewport: \"div\",\n  output: \"div\",\n  line: \"div\",\n  jump: \"button\",\n});\n\nexport type TerminalProps = ComponentProps<typeof parts.Root>;\n\n/**\n * A command and its output as a step: the command, its exit code and duration, its approval while it has one, then\n * the output with its ANSI colors, following its end while it streams. Any `children` replace the default parts.\n */\nexport function Terminal({ children, ...props }: TerminalProps) {\n  return <parts.Root {...props}>{children !== undefined ? children : DEFAULT_PARTS}</parts.Root>;\n}\n\nexport const TerminalTrigger = parts.Trigger;\nexport const TerminalIcon = parts.Icon;\nexport const TerminalContent = parts.Content;\nexport const TerminalCopy = parts.Copy;\n/** Scrolls the output and follows its end. Holds a `TerminalOutput`. */\nexport const TerminalViewport = parts.Viewport;\n\nexport type TerminalTitleProps = ComponentProps<typeof parts.Title>;\n\n/** The command, or the `label`, or \"Run <command>?\" while the approval waits, unless you pass children. */\nexport function TerminalTitle({\n  children = ({ spans }) =>\n    // biome-ignore lint/suspicious/noArrayIndexKey: the pieces never move.\n    spans.map((piece, index) =>\n      index % 2 ? <code key={index}>{piece}</code> : <Fragment key={index}>{piece}</Fragment>,\n    ),\n  ...props\n}: TerminalTitleProps) {\n  return <parts.Title {...props}>{children}</parts.Title>;\n}\n\nexport type TerminalExitProps = ComponentProps<typeof parts.Exit>;\n\n/** \"Exit N\" once there's an exit code other than 0, unless you pass children. */\nexport function TerminalExit({ children = ({ text }) => text, ...props }: TerminalExitProps) {\n  return <parts.Exit {...props}>{children}</parts.Exit>;\n}\n\nexport type TerminalMetaProps = ComponentProps<typeof parts.Meta>;\n\n/** \"Waiting for approval\" while the approval waits, else the duration as \"6 sec\", unless you pass children. */\nexport function TerminalMeta({ children = ({ text }) => text, ...props }: TerminalMetaProps) {\n  return <parts.Meta {...props}>{children}</parts.Meta>;\n}\n\nexport type TerminalApprovalProps = ComponentProps<typeof parts.Approval>;\n\n/**\n * A Confirmation for the command's approval while it has one: the choices whose callbacks are set while the request\n * waits, then what was decided. Pass children to render it yourself.\n */\nexport function TerminalApproval({\n  children = (confirmation) => <Confirmation {...confirmation} />,\n  ...props\n}: TerminalApprovalProps) {\n  return <parts.Approval {...props}>{children}</parts.Approval>;\n}\n\nexport type TerminalCommandProps = ComponentProps<typeof parts.Command>;\n\n/**\n * The command after its prompt, which the stylesheet draws, unless you pass children. Present only while a `label`\n * replaces the command as the title.\n */\nexport function TerminalCommand({ children = ({ command }) => command, ...props }: TerminalCommandProps) {\n  return <parts.Command {...props}>{children}</parts.Command>;\n}\n\nexport type TerminalOutputProps = ComponentProps<typeof parts.Output>;\n\n/** A `TerminalLine` for each line in view, unless you pass children. */\nexport function TerminalOutput({\n  children = ({ rows }) => rows.map((row) => <TerminalLine key={row.index} index={row.index} />),\n  ...props\n}: TerminalOutputProps) {\n  return <parts.Output {...props}>{children}</parts.Output>;\n}\n\nconst spanStyle = (span: AnsiSpan) =>\n  span.fg || span.bg ? { color: span.fg, backgroundColor: span.bg } : undefined;\n\nexport type TerminalLineProps = ComponentProps<typeof parts.Line>;\n\n/**\n * One line of output, its `index`th, as styled spans, unless you pass children. Memoized, so a line that moved or\n * didn't change isn't rendered again when the lines in view change.\n */\nexport const TerminalLine = memo(function TerminalLine({\n  value,\n  children = ({ spans }) =>\n    spans.map((span, index) => (\n      <span\n        key={index}\n        style={spanStyle(span)}\n        data-bold={span.bold ? \"\" : undefined}\n        data-dim={span.dim ? \"\" : undefined}\n        data-italic={span.italic ? \"\" : undefined}\n        data-underline={span.underline ? \"\" : undefined}\n        data-strike={span.strike ? \"\" : undefined}\n      >\n        {span.text}\n      </span>\n    )),\n  ...props\n}: TerminalLineProps) {\n  return (\n    <parts.Line value={value ?? String(props.index)} {...props}>\n      {children}\n    </parts.Line>\n  );\n});\n\nexport type TerminalJumpProps = ComponentProps<typeof parts.Jump>;\n\n/** Shown while the reader has scrolled away from the end. \"Jump to latest\", unless you pass children. */\nexport function TerminalJump({ children = \"Jump to latest\", ...props }: TerminalJumpProps) {\n  return <parts.Jump {...props}>{children}</parts.Jump>;\n}\n\n// Shared, so new output doesn't render the default parts' wrappers again.\nconst DEFAULT_PARTS = (\n  <>\n    <TerminalTrigger>\n      <TerminalIcon />\n      <TerminalTitle />\n      <TerminalExit />\n      <TerminalMeta />\n    </TerminalTrigger>\n    <TerminalApproval />\n    <TerminalContent>\n      <div data-terminal-screen=\"\" data-kind-code=\"\">\n        <div data-terminal-header=\"\">\n          <TerminalCommand />\n          <TerminalCopy />\n        </div>\n        <TerminalViewport>\n          <TerminalOutput />\n        </TerminalViewport>\n        <TerminalJump />\n      </div>\n    </TerminalContent>\n  </>\n);\n",
      "type": "registry:ui",
      "target": "@ui/terminal.tsx"
    }
  ],
  "meta": {
    "layer": "react"
  },
  "type": "registry:ui"
}
