nteract elements

ANSI Output

Components for rendering ANSI escape sequences as colored terminal output in notebook cells

Components for rendering ANSI escape sequences as colored text. Preserves the terminal colors developers expect from stdout, stderr, and error tracebacks.

Installation

npx shadcn@latest add https://nteract-elements.vercel.app/r/ansi-output.json

Install the dependency:

npm install ansi-to-react

Copy the component to your project from the registry source.

Components

This package exports three components:

ComponentPurpose
AnsiOutputBase component for rendering ANSI text
AnsiStreamOutputSpecialized for stdout/stderr streams
AnsiErrorOutputSpecialized for error tracebacks

Usage

AnsiOutput

The base component for rendering any text with ANSI escape sequences.

import { AnsiOutput } from "@/registry/outputs/ansi-output"

export function Example() {
  const text = "\x1b[32mSuccess:\x1b[0m Operation completed"
  
  return <AnsiOutput>{text}</AnsiOutput>
}
Success: Operation completed

Here's a more colorful example:

Black Red Green Yellow Blue Magenta Cyan White

Props

PropTypeDefaultDescription
childrenstringThe text containing ANSI escape sequences
classNamestring""Additional CSS classes
isErrorbooleanfalseApplies error styling (red text)

AnsiStreamOutput

Renders stdout or stderr output with appropriate styling.

import { AnsiStreamOutput } from "@/registry/outputs/ansi-output"

export function StreamExample() {
  return (
    <>
      <AnsiStreamOutput 
        text="Hello from stdout" 
        streamName="stdout" 
      />
      <AnsiStreamOutput 
        text="Warning: something went wrong" 
        streamName="stderr" 
      />
    </>
  )
}
stdout
Installing dependencies... numpy pandas matplotlib
stderr
DeprecationWarning: use_categorical is deprecated

Props

PropTypeDefaultDescription
textstringThe stream text to render
streamName"stdout" | "stderr"Stream type (stderr renders in red)
classNamestring""Additional CSS classes

AnsiErrorOutput

Renders Python-style error tracebacks with proper formatting.

import { AnsiErrorOutput } from "@/registry/outputs/ansi-output"

export function ErrorExample() {
  return (
    <AnsiErrorOutput
      ename="ValueError"
      evalue="invalid literal for int() with base 10: 'abc'"
      traceback={[
        "Traceback (most recent call last):",
        '  File "<stdin>", line 1, in <module>',
        "ValueError: invalid literal for int() with base 10: 'abc'"
      ]}
    />
  )
}
ValueError: invalid literal for int() with base 10: 'abc'
Traceback (most recent call last): File "<stdin>", line 1, in <module> int('abc') ValueError: invalid literal for int() with base 10: 'abc'

Props

PropTypeDefaultDescription
enamestringException name (e.g., "ValueError")
evaluestringException value/message
tracebackstring[] | stringTraceback lines (array or joined string)
classNamestring""Additional CSS classes

ANSI Color Reference

Common ANSI escape sequences rendered by these components:

CodeColorExample
\x1b[30mBlack
████
\x1b[31mRed
████
\x1b[32mGreen
████
\x1b[33mYellow
████
\x1b[34mBlue
████
\x1b[35mMagenta
████
\x1b[36mCyan
████
\x1b[37mWhite
████
\x1b[0mReset

On this page