ANSI terminal emulation and conversion to ANSI, HTML, and plain text
erbsland-ansi-convert is a Python 3.10+ library that simulates an ANSI terminal and converts the resulting terminal history into:
- Plain text
- Compact ANSI text
- Compact HTML with CSS classes
It is designed to process terminal output from tools that emit ANSI escape sequences and render a static representation close to what users see in a real terminal.
Installation
pip install erbsland-ansi-convert
Quick Start
from pathlib import Path
from erbsland.ansi_convert import Terminal
terminal = Terminal(width=120, height=40, back_buffer_height=2000)
terminal.write(Path("path/to/output.log").read_text())
Path("out.txt").write_text(terminal.to_text())
Path("out.ansi.txt").write_text(terminal.to_ansi())
Path("out.visible-esc.txt").write_text(terminal.to_ansi(esc_char="␛"))
Path("out.html").write_text(terminal.to_html(class_prefix="my-ansi"))
For terminal capture files, prefer writeFile() to preserve carriage returns:
terminal = Terminal()
terminal.writeFile("capture-via-script-cmd.txt")
If your input text already normalized carriage returns to newlines, you can enable
the progress-line collapse heuristic on write():
terminal.write(text, collapse_capture_updates=True)
Command Line
Installing the package also installs the erbsland-ansi-convert command:
erbsland-ansi-convert [-f/--format (text|ansi|html)] [-c|--collapse] [-C|--no-collapse] [-o/--output <file>] [<input file>|-]
-f,--format: output format (text,ansi,html), defaultansi-o,--output: write output to file, default stdout-c,--collapse: enable collapse heuristic-C,--no-collapse: disable collapse heuristic<input file>: input capture file, or-for stdin
Supported Terminal Features
- Control characters:
BEL,BS,HT,LF,VT,FF,CR,DEL - Cursor controls (
CSI A/B/C/D/E/F/G/H/f,ESC M, save/restore variants) - Erase functions (
CSI J,CSI Kincluding mode3Jfor saved lines) - SGR text styles (
bold,dim,italic,underline,blink,reverse,hidden,strike) - Basic + bright 8 ANSI colors for foreground/background
- Common private modes: cursor visibility (
?25) and alternate buffer (?47,?1049)
Unknown sequences can optionally be reported as warnings.
HTML Output Model
to_html() produces:
<div class="{prefix}-block"><pre>...</pre></div>
Text styles are represented with flat span classes such as:
{prefix}-bold{prefix}-red{prefix}-background-blue
Spans are reopened only when style actually changes to keep output compact and easy to style.
Development
Install development dependencies:
pip install -r requirements-dev.txt
Run tests:
pytest
License
Copyright (c) 2026 Tobias Erbsland / Erbsland DEV (https://erbsland.dev)
Licensed under the Apache License, Version 2.0.
See LICENSE for details.
Metadata
Release files for erbsland-ansi-convert 0.9.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| erbsland_ansi_convert-0.9.1.tar.gz | 31.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| erbsland_ansi_convert-0.9.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 55.3 kB
Release files / erbsland_ansi_convert-0.9.1.tar.gz
| Download URL | erbsland_ansi_convert-0.9.1.tar.gz |
|---|---|
| Size | 31.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7d7e5431c735ccdee3f55937773e3833eb7e20775629b31924b1c06c0d1bdf21
|
|
BLAKE2b-256 checksum How to use checksums |
68cd1ff8edcc68ba7652499ef358367ce55b893343fbaada8c3d1cac9e439bd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 19, 2026.
Transparency logRelease files / erbsland_ansi_convert-0.9.1-py3-none-any.whl
| Download URL | erbsland_ansi_convert-0.9.1-py3-none-any.whl |
|---|---|
| Size | 24.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f691fde8463992bc38165543c8e6974afb2878657acd9a8be677b7286ed238ad
|
|
BLAKE2b-256 checksum How to use checksums |
fa04f763ba1f28d32943330feb4f621ff3ada9a5f424fb536cafba1558e88221
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 19, 2026.
Transparency log