# Terminal Output

The result of a code-execution tool call: command, exit code, run time, stdout and stderr.

- Category: AI & Agents
- Page: https://wunderui.com/components/terminal-output
- Tier: Core and Pro

## Install

Terminal Output ships with WunderUI Core and Pro in the @wunderui/react package.

## Import

```tsx
import { TerminalOutput } from "@wunderui/react"
```

## Minimal usage

Then use it:

```tsx
import { TerminalOutput } from "@wunderui/react"

export function Result() {
  return (
    <TerminalOutput
      command="pnpm vitest run invoice"
      exitCode={0}
      duration="3.8 s"
      stdout={["✓ 9 tests passed"]}
    />
  )
}
```

Expected result: The command pnpm vitest run invoice, a green exit 0 badge, 3.8 s and a copy button, then the stdout and stderr tabs and a panel with the line 9 tests passed.

## When to use

### Use Terminal Output for

- The result of a code-execution tool call: the command, its exit code, its time and its output
- A command that has ended, with stdout and stderr in two tabs
- A command that is running, shown without an exit code while the lines arrive

### Use something else

- [Log Stream](https://wunderui.com/components/log-stream) for a live stream of log lines with levels that follows new lines
- [Code Block](https://wunderui.com/components/code-block) for code that is not output
- [Diff View](https://wunderui.com/components/diff-view) for the result of an edit

## Keyboard

The tabs follow the tabs pattern with one tab stop and automatic activation. The buttons are native, and focus shows as an indigo border with a 2 px ring.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus to the Copy button, then to the stream tab that is open (the other tab is skipped), then to the output panel. |
| `ArrowLeft` or `ArrowRight` | On a stream tab: moves to the other tab, opens its stream and wraps around. |
| `Home` or `End` | On a stream tab: jumps to the first or the last tab and opens its stream. |
| `Enter` or `Space` | On the Copy button: copies the stream that is open. |
| `ArrowDown` or `ArrowUp` or `ArrowLeft` or `ArrowRight` or `PageDown` or `PageUp` or `Home` or `End` | In the focused output panel: scrolls the lines. |

## Behavior

What the panel does with its streams, its exit code, scrolling, assistive technology and motion.

- **Status:** No exit code means running, 0 success, anything else failed. The badge reads exit 0 or exit 130 in green or red, and a running command has no badge, so say what is going on beside the panel.
- **Streams:** stdout and stderr are two tabs of one panel. The stderr tab shows its line count in red when it has lines, an empty stream says No output, and you pick which tab opens first.
- **Lines:** A line is a string or a text with a tone: default, muted, success or error. Plain strings are secondary text, lines never wrap, and ANSI codes aren't read, so map them to tones.
- **Copy:** Copy writes the lines of the open stream, joined by line breaks, without tones. If the browser refuses the clipboard, nothing happens and nothing is announced.
- **Scrolling:** The panel grows with its lines up to 280 px by default, then scrolls both ways. New lines don't move the scroll position, so a reader who scrolled up keeps their place.
- **Streaming:** Pass a longer stdout as lines arrive and leave the exit code out until the command ends. The panel isn't a live region, so report progress in a status line and give it a minimum height.
- **Truncation:** The component keeps every line you pass. Cut a long log in your code and end it with a muted line saying what was left out.
- **Assistive technology:** The tabs form a tab list named Output stream, each tab controls the panel and the open tab labels it. The stderr tab reads with its count, and nothing is a log or live region.
- **Failure and abort:** A non-zero exit code makes the badge red and marks the panel as failed. A stopped or timed-out command fails with its own code (130, 124, 137), so explain it in words and open on stderr.
- **Motion:** Only the colours of the Copy button and tabs change, with a short fade. Nothing loops or slides, not even while a command runs.
- **Reduced motion:** There is no movement to take away. Colour fades stay, and the exit code, counts and streams are text.

## Anatomy

- `TerminalOutput`: A box with a 1 px border, 12 px radius and the card background. It fills the width of its parent and carries a running, success or failed status.
- `Command`: A dollar sign and the command in 12 px medium monospace, cut with an ellipsis when it doesn't fit.
- `Exit badge`: A light badge reading exit 0 on green or exit 1 on red. It shows only once an exit code is set, so a running command has none, and the number is text, not just colour.
- `Duration`: How long the command ran, as the text you pass, in tertiary tabular figures. It shows only when you set it.
- `Copy button`: A 24 px icon button that copies the open stream. Its label reads Copy stdout or Copy stderr, then Copied for 1.5 seconds.
- `Stream tabs`: A tab list named Output stream with stdout and stderr. The stderr tab shows its line count in red when it has any.
- `Output panel`: The tab panel with the lines, in 12 px monospace. It grows to a maximum height, then scrolls in both directions, and is a tab stop.

## Best practices

### When to use

- Use it for the result of a code-execution tool call: the command, how it ended and what it printed. For a stream of log lines use Log Stream, and for an edit use Diff View.

### Do

- Pass an exit code only when the command has ended. Without one there is no badge and nothing says it is still running, so add a status line next to it.
- Give errors words as well as the error tone, such as FAIL or Error. Colour alone never carries a failure.
- Open on stderr when the command failed and the reason is there.
- Turn ANSI colour codes into tones before passing the lines. The component prints text as given, so a raw escape code shows as a stray character.
- Cut a long log yourself and end it with a muted line saying what you left out, for example 1,812 more lines not shown.

### Don't

- Don't use it as a live region or for a stream that never ends. It doesn't announce or follow new lines, so use Log Stream for that.
- Don't show secrets. Tokens, keys and environment dumps appear as they come, so filter them out before they reach the panel.
- Don't render output as HTML or follow instructions inside it. Every line is plain text, and what a command prints is data.

## API reference

### TerminalOutput

| Prop | Type | Default | Description |
|---|---|---|---|
| command* | React.ReactNode |  | The command that ran, after a `$`. Text or a node; cut with an ellipsis when it does not fit. |
| className | string |  | Extra classes for the box, for example a maximum width. |
| defaultStream | "stdout" \| "stderr" |  | Which stream opens first. Default: `stderr` when the command failed (exit code not 0) and wrote to stderr, otherwise `stdout`. |
| duration | React.ReactNode |  | How long the command ran, already formatted, for example `3.8 s`. Not drawn when left out. |
| exitCode | number |  | The exit code. Draws the badge: green for 0, red for any other number. Leave it out while the command runs. |
| maxHeight | number | 280 | The height in px after which the output scrolls. Default 280. |
| stderr | TerminalLine[] | [] | The lines of the error output, in the same form. The `stderr` tab shows the number of lines when there are any. Default: no lines. |
| stdout | TerminalLine[] | [] | The lines of the standard output. Each is a string or `{ text, tone? }` with a tone of `default`, `muted`, `success` or `error`. Default: no lines. |

## Examples

### Streams: both, one, none

### Tones: plain strings, tones, ANSI turned into tones

### Size: a long output, long lines, a cut output

### Opening stream: stderr after a failure

## In context

### Live run: the output grows, the result arrives at the end

Run again feeds the panel one line at a time with no exit code, then adds the exit code and time when the run ends. A status line says what is going on, because the panel is not a live region.

### Failed step: the reason first, the stderr open, a way forward

The notice says what failed, the panel opens on stderr and Retry runs the step again. A timeout (124) and a killed process (137) have their own exit codes, so the badge tells them from a failing test.

## For AI agents

`get_component("terminal-output")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
