Skip to documentation content

Terminal Output

Show a command an agent ran and its output as it streams, with the exit status and a copy button.

terminal-output-demo

Overview

Terminal Output shows a command an agent ran and what it printed. Append to lines as output arrives; the block follows the newest line, shows how long the command has been running, and reports the exit code when you pass it.

Output is shown as plain text, with its spacing kept. Strip ANSI color codes before passing lines in. Error output is passed with stream: "stderr" and shows in the danger color.

Anatomy

TerminalOutput
  • HeaderThe working directory, the prompt sign, the command, the status, and Copy
  • OutputThe lines, in a scrolling block that follows the newest one
  • Jump to latestA button that appears when the reader scrolls up while output arrives

Behavior

Running

While exitCode is missing, the command counts as running. The header shows a spinner and a clock that counts whole seconds from startedAt, or from when the block first showed. Pass running for a command that finished without an exit code.

Exit status

When the command finishes, the header shows "Exit 0" and the duration, in the secondary color. A nonzero exit turns the status the danger color. A finished command is announced once, as "Command finished" or with its exit code.

Following output

The output scrolls itself to the newest line while the reader is at the end. Scrolling up stops it, and a Jump to latest button appears at the bottom; it scrolls back down and resumes following.

Long output

Once the command finishes, output longer than collapsedLines shows only its last lines, under a row that says how many earlier lines are hidden. That row shows them all, and Show less folds them away again. While the command runs, every line stays.

Copy

Copy puts the output on the clipboard, without the command, and the icon becomes a check for a moment. If the browser refuses clipboard access, the block says "Copy failed".

Accessibility

The block is a figure captioned by the command. The output is a group named "Output"; when it scrolls, it takes focus so it can be scrolled from the keyboard. The prompt sign is hidden from assistive technology. Status changes are announced through a polite status, and error lines are marked by color and by their own text.

KeyAction
TabMove to Copy, Show earlier lines, the output, and Jump to latest
Arrow keysScroll the focused output

Installation

npx honestui@latest add terminal-output

Usage

import { TerminalOutput } from "@/components/ai/terminal-output"

<TerminalOutput command={run.command} lines={run.lines} startedAt={run.startedAt} />

<TerminalOutput
  command="npm test"
  cwd="~/app"
  lines={run.lines}
  exitCode={run.exitCode}
  duration={run.duration}
/>

Examples

Failure

A test run that exited with 1. Its passing lines fold away, and the failure stays in view.

terminal-output-failure

API reference

TerminalOutput

Accepts native figure props beyond those listed.

PropTypeDefaultDescription
commandstringRequiredThe command that ran.
linesTerminalLine[]RequiredThe output, in order.
cwdstringNoneThe working directory, shown before the command.
exitCodenumberNoneThe exit code. Missing means running.
runningbooleanexitCode === undefinedOverrides the running state.
startedAtnumberWhen it first showedWhen the command started, in epoch milliseconds.
durationnumberNoneHow long it took, in milliseconds.
collapsedLinesnumber20How many last lines a finished command shows before it is expanded.
actionsReactNodeNoneControls for the header, placed before Copy.
onCopy(text: string) => voidNoneRuns after the output reaches the clipboard.
labelsPartial<TerminalOutputLabels>EnglishStates, counts, and the duration format.

Types

ExportShape
TerminalLinetext, and optional stream of "stdout" or "stderr"