aiellie

Search

Find a component, template or page

GitHub
Components

Terminal

A command and what came back: the prompt and the command highlighted as shell, its output, and a line that says whether it is running, done or failed.

Terminal
pnpm typecheck
> tsc --noEmit
Done
pnpm lint --max-warnings 0
app/page.tsx
  12:7  error  'user' is assigned a value but never used
Exited with 1
Open full screen
fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/terminal"

shadcn needs the @aiellie registry in components.json first. npx aiellie add terminal adds it on its first run, then installs the same way.

Terminal shows a run rather than a line to run: the command after its prompt, coloured as shell, what it printed, and a status line saying whether it's running, finished, or failed with its exit code. It goes inside a CodeBlock, so the frame, title and copy work as they do for code.

Getting started

  1. Show a run

    components/run.tsx
    import {
      CodeBlock,
      CodeBlockHeader,
      CodeBlockTitle,
    } from "@/components/aiellie/code-block"
    import {
      TerminalCommand,
      TerminalContent,
      TerminalOutput,
      TerminalStatus,
    } from "@/components/aiellie/terminal"
    
    export function Run({
      command,
      output,
      exitCode,
    }: {
      command: string
      output: string
      exitCode: number | null
    }) {
      return (
        <CodeBlock>
          <CodeBlockHeader>
            <CodeBlockTitle icon={null}>Terminal</CodeBlockTitle>
          </CodeBlockHeader>
          <TerminalContent>
            <TerminalCommand>{command}</TerminalCommand>
            <TerminalOutput tone={exitCode ? "error" : "default"}>
              {output}
            </TerminalOutput>
            <TerminalStatus
              status={exitCode === null ? "running" : exitCode ? "error" : "success"}
              exitCode={exitCode ?? undefined}
            />
          </TerminalContent>
        </CodeBlock>
      )
    }

Anatomy

<div data-slot="terminal-content" dir="ltr">
  <div data-slot="terminal-command" /> {/* $ pnpm build */}
  <pre data-slot="terminal-output" data-tone="default | error" />
  <div data-slot="terminal-status" data-status="running | success | error" />
</div>

The prompt is left out of a selection, so a copied command pastes as a command. Several runs stack in one TerminalContent, each new command set a little apart from the run before.

The status mark is the Status dot: live and pulsing while it runs, then success or destructive, always with a word beside it.

Examples

While it runs

Append output as it arrives and keep the status on running until the command exits.

Terminal
pnpm vitest run
Running

Your own prompt

<TerminalCommand prompt="~/app ❯">pnpm dev</TerminalCommand>

API reference

TerminalCommand

PropTypeDefaultDescription
childrenstringrequiredWhat was typed.
promptstring"$"The mark before it, left out of a copy.

All other div props are forwarded.

TerminalOutput

PropTypeDefaultDescription
tone"default" | "error""default"error sets the output in the destructive ink.

All other pre props are forwarded.

TerminalStatus

PropTypeDefaultDescription
status"running" | "success" | "error"requiredWhere the run is.
exitCodenumberSaid after a failure, like "Exited with 1".
childrenReactNodeWords of your own in place of "Running", "Done" or the exit code.

All other div props are forwarded.