ANSI terminal emulation and conversion to ANSI, HTML, and plain text
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file erbsland_ansi_convert-0.9.1.tar.gz.
File metadata
- Download URL: erbsland_ansi_convert-0.9.1.tar.gz
- Upload date:
- Size: 31.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d7e5431c735ccdee3f55937773e3833eb7e20775629b31924b1c06c0d1bdf21
|
|
| MD5 |
36b24dc541747312d46c9bfa6b61aa58
|
|
| BLAKE2b-256 |
68cd1ff8edcc68ba7652499ef358367ce55b893343fbaada8c3d1cac9e439bd8
|
Provenance
The following attestation bundles were made for erbsland_ansi_convert-0.9.1.tar.gz:
Publisher:
publish.yml on erbsland-dev/erbsland-py-ansi-convert
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
erbsland_ansi_convert-0.9.1.tar.gz -
Subject digest:
7d7e5431c735ccdee3f55937773e3833eb7e20775629b31924b1c06c0d1bdf21 - Sigstore transparency entry: 969491242
- Sigstore integration time:
-
Permalink:
erbsland-dev/erbsland-py-ansi-convert@fc9b915aa51081831dd409fd40f9a386fc1c9f79 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/erbsland-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fc9b915aa51081831dd409fd40f9a386fc1c9f79 -
Trigger Event:
release
-
Statement type:
File details
Details for the file erbsland_ansi_convert-0.9.1-py3-none-any.whl.
File metadata
- Download URL: erbsland_ansi_convert-0.9.1-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f691fde8463992bc38165543c8e6974afb2878657acd9a8be677b7286ed238ad
|
|
| MD5 |
2f5e5d59a9483f575ef489c8854c36b2
|
|
| BLAKE2b-256 |
fa04f763ba1f28d32943330feb4f621ff3ada9a5f424fb536cafba1558e88221
|
Provenance
The following attestation bundles were made for erbsland_ansi_convert-0.9.1-py3-none-any.whl:
Publisher:
publish.yml on erbsland-dev/erbsland-py-ansi-convert
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
erbsland_ansi_convert-0.9.1-py3-none-any.whl -
Subject digest:
f691fde8463992bc38165543c8e6974afb2878657acd9a8be677b7286ed238ad - Sigstore transparency entry: 969491245
- Sigstore integration time:
-
Permalink:
erbsland-dev/erbsland-py-ansi-convert@fc9b915aa51081831dd409fd40f9a386fc1c9f79 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/erbsland-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fc9b915aa51081831dd409fd40f9a386fc1c9f79 -
Trigger Event:
release
-
Statement type: