ERBSLAND ANSI CONVERT

A Python library and CLI tool for ANSI terminal emulation and conversion

Language Python
License Apache 2.0

Erbsland ANSI Convert is a Python 3.10+ library and CLI tool that emulates ANSI terminal behavior and converts terminal output into static, shareable formats.

It is designed for terminal logs and captured command output where color, cursor movement, and styling matter, while keeping integration simple and dependency-free at runtime.

Installation and Quick Example

Install the package from PyPI:

pip install erbsland-ansi-convert

Use the Terminal API to parse ANSI output and export it as text, ANSI, or HTML:

from erbsland.ansi_convert import Terminal

terminal = Terminal(width=120, height=40, back_buffer_height=2000)
terminal.write("\x1b[31mHello\x1b[0m")

plain_text = terminal.to_text()
ansi_text = terminal.to_ansi()
html_output = terminal.to_html(class_prefix="my-ansi")

Key Features

Erbsland ANSI Convert focuses on practical conversion of terminal captures while preserving what users actually saw:

  • Simulates a configurable terminal screen and scroll-back history.
  • Parses common ANSI cursor movement, erase commands, style, and color sequences.
  • Converts output to compact plain text, compact ANSI text, or compact HTML.
  • Supports optional warnings for unknown or unsupported sequences.
  • Handles both library usage and command-line workflows with the same conversion logic.

Ready to Convert ANSI Output?

Get started in minutes and convert colored terminal output into clean text, ANSI, or HTML for reports, docs, and archives.

Command Line Tool

Installing the package also provides the erbsland-ansi-convert command:

erbsland-ansi-convert [-f/--format (text|ansi|html)] [-c|--collapse]
                      [-C|--no-collapse] [-o/--output <file>]
                      [<input file>|-]

Important options:

  • -f, --format selects the output format (text, ansi, html), default is ansi.
  • -o, --output writes to a file instead of standard output.
  • -c, --collapse enables progress-line collapsing for normalized captures.
  • -C, --no-collapse disables collapsing explicitly.

This makes it easy to integrate conversion into scripts, CI logs, or documentation pipelines.

Requirements

Runtime requirements are intentionally minimal:

  • Python 3.10 or newer
  • No runtime dependencies outside the Python standard library

For development, the project provides a requirements-dev.txt file and uses standard Python tooling such as pytest, black, hatch, and hatch-vcs.

HTML Output and Styling

The HTML exporter generates compact markup with predictable CSS classes, so ANSI-rendered output is easy to style in your own UI or docs.

You can control the CSS prefix via class_prefix:

# ...
html_output = terminal.to_html(class_prefix="my-ansi")

This keeps styling isolated and makes integration straightforward in existing design systems.

Explore the Full API

Dive into the API reference to see all terminal, parser, and converter classes in detail.

Sources and License

The complete source code for Erbsland ANSI Convert is available on GitHub.

The project is licensed under the Apache License 2.0, allowing use in both open-source and proprietary projects.