Command
ProA command the agent ran: the row reads Ran pnpm test · 4.2 s and folds a well with the command, Copy and what it printed. Running, its output prints in, the clock ticks and Stop ends it; a failure reads red with its exit code.
npx shadcn@latest add @pixilui-pro/commandPreview
import { useEffect, useRef } from "react";
import { Button } from "../../../registry/ui/button/button";
import { Command, type CommandHandle } from "@/components/pixilui/command";
import { failedOutput, listenLines, listenReady, testOutput } from "@/components/pixilui/command.examples";
// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
state: ["done", "running", "failed", "stopped"],
} as const;
const ANSWER = { fontSize: "var(--pixilui-text-answer)", lineHeight: "var(--pixilui-text-answer-leading)", letterSpacing: "var(--pixilui-text-answer-tracking)" };
const SAID = {
running: "Forwarding Stripe's webhooks to your local server, so you can watch the refund arrive.",
done: "All 10 refund tests pass with the new limit.",
failed: "Typecheck found one error: review.ts uses db without importing it. Fixing that next.",
stopped: "Stopped forwarding webhooks once the refund arrived.",
};
/** A command the agent ran: running, its output prints in and Stop ends it; done, failed with its exit code, or stopped. */
export default function CommandDemo({ state = "done" }: KnobValues<typeof knobs>) {
const ref = useRef<CommandHandle>(null);
useEffect(() => {
if (state === "running") ref.current?.stream(listenLines, 1400);
}, [state]);
const props =
state === "running" ? { cmd: "stripe listen --forward-to localhost:3000/api/webhooks", state, output: listenReady }
: state === "done" ? { cmd: "pnpm test refunds", state, time: 4.2, output: testOutput }
: state === "failed" ? { cmd: "pnpm typecheck", state, exit: 2, time: 2.8, output: failedOutput }
: { cmd: "stripe listen --forward-to localhost:3000/api/webhooks", state, time: 18.6, output: [...listenReady, ...listenLines.slice(0, 4), "^C"] };
return (
<div className="grid w-full max-w-xl gap-3 rounded-panel bg-surface p-5 elevation-raised">
<p className="m-0 text-foreground" style={ANSWER}>
{SAID[state]}
</p>
<Command key={state} ref={ref} {...props} />
{state === "running" ? (
<div>
<Button
variant="secondary-2"
size="sm"
onClick={() => {
ref.current?.restart();
ref.current?.stream(listenLines, 1400);
}}
>
Run it again
</Button>
</div>
) : null}
</div>
);
}When to use
Use it when
- A command the agent ran in a terminal, with what it printed: tests, a build, a CLI that streams.
- A long-running command the person may stop.
Use something else when
- A tool call with JSON arguments and a result: use Tool call.
- Code the agent wrote: use Code block.
Installation
Join the waitlist and we'll email you when PixilUI launches. The preview, props and docs stay open until then.
Pro installs with the same CLI as the free items. One command adds command.tsx and the free button.tsx, the free kbd.tsx, the free tooltip.tsx and the free code-block.tsx it uses; your license key goes in once, as in Installation.
{
"registries": {
"@pixilui-pro": {
"url": "https://pixilui.com/r/pro/{name}.json",
"headers": { "Authorization": "Bearer ${PIXILUI_TOKEN}" }
}
}
}npx shadcn@latest add @pixilui-pro/commandAdds command.tsx with button.tsx, kbd.tsx, tooltip.tsx and code-block.tsx, and installs clsx and tailwind-merge. The CLI reads PIXILUI_TOKEN from .env.local; if this computer has not logged in yet, run npx pixilui@latest login once.
components/pixilui/command.tsxthe item, 315 linescomponents/pixilui/button.tsxused inside, freecomponents/pixilui/kbd.tsxused inside, freecomponents/pixilui/tooltip.tsxused inside, freecomponents/pixilui/code-block.tsxused inside, freeIt uses Button, Kbd, Tooltip and Code block: add them the same way. Then npm i clsx tailwind-merge, and add the foundation once per app, as in Installation.
Usage
import { Command } from "@/components/pixilui/command";
<Command
cmd={cmd}
onOpenChange={onOpenChange}
onStop={onStop}
/>Fills its container; output wraps with a hanging indent, so a wrapped line stays one entry.
API reference
cmdRequiredstring–The command: "pnpm test refunds". The row shows its first two words.outputstring[][]The lines it printed. While it runs, lines added here print in.timenumber0How long it ran, in seconds (running: where its clock starts).state"done" | "running" | "failed" | "stopped""done"done (the default), running, failed or stopped.exitnumber0The exit code of a command that failed.defaultOpenbooleantrueOpen (default) or folded, uncontrolled.openboolean–Open or folded, controlled.onOpenChange(open: boolean) => void–The row was pressed.onStop() => void–Stop was pressed (it stops itself; stop the process too).wordsPartial<CommandWords>–Every word it says.icons{ chevron?: ReactNode; stop?: ReactNode; copy?: ReactNode }{}The icons it draws (the locked disclosure, stop-run and copy-check).Also takes every native <section> attribute except onToggle, and a ref.
Keyboard
Accessibility
- The output is a log (aria-live polite while it runs); after Stop focus moves to the row and the status line says how long it ran.
- Copy copies the command itself; a key in the output (sk_live_, whsec_, ghp_) renders masked, named with its last four.
- Failed and Stopped are words, not only color.
Motion
- A new line writes in from its left edge as it prints; the view follows the end unless you scrolled up to read.
- The clock ticks in tabular figures with no motion of its own; the row's verb and Stop swap with the quiet blur swap.
- Reduced motion: lines appear at once.