A Sphinx extension to format ANSI colored/formated terminal output
Project description
ANSI-Colored Terminal Output for Sphinx
erbsland-sphinx-ansi is a lightweight Sphinx extension that renders ANSI-colored and formatted terminal output directly in your documentation.
It is useful for command-line tools, build logs, and terminal sessions where ANSI colors improve readability.
Features
- Render ANSI-colored terminal output in Sphinx documentation.
- Support for standard ANSI text styles and colors.
- Optional
escape-charparameter for readable source files. - Optional
themeparameter for custom CSS styling. - Works with both HTML and non-HTML output formats.
Installation
pip install erbsland-sphinx-ansi
Quick Start
Enable the extension in conf.py:
extensions = [
# ...
"erbsland.sphinx.ansi",
]
Use the erbsland-ansi directive:
.. erbsland-ansi::
:escape-char: ␛
␛[32m[sphinx-autobuild] ␛[36mStarting initial build␛[0m
␛[32m[sphinx-autobuild] ␛[34m> python -m sphinx build doc _build␛[0m
␛[32m[sphinx-autobuild] ␛[36mServing on http://127.0.0.1:9000␛[0m
␛[32m[sphinx-autobuild] ␛[36mWaiting to detect changes...␛[0m
escape-char is optional. If set, this character is replaced with the ANSI escape character (\x1b) when parsing the directive content. If omitted, provide real ANSI escape sequences directly.
Output Formats
- HTML output: ANSI sequences are converted into styled output.
- Non-HTML output: ANSI formatting is stripped, leaving plain text.
Limitations
erbsland-sphinx-ansi renders ANSI text formatting but is not a terminal emulator.
The extension supports ANSI colors and text styles, but does not emulate terminal behavior such as:
- Cursor movement
- Screen clearing
- Alternate screen buffers
- Character-set switching
- Interactive terminal updates
Output that relies on terminal emulation may not render as expected.
For such cases, preprocess the captured output with erbsland-ansi-convert:
pip install erbsland-ansi-convert
erbsland-ansi-convert input.ansi -o output.ansi
This tool emulates a terminal and writes the final screen contents as ANSI-formatted text that can be rendered correctly by erbsland-sphinx-ansi.
Requirements
- Python 3.10+
- Sphinx 8.0+ (required by the extension at runtime)
Development
- Python 3.13+
Install development dependencies:
pip install -r requirements-dev.txt
Run tests:
pytest
Documentation
Project documentation is available at:
https://sphinx-ansi.erbsland.dev
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_sphinx_ansi-1.2.4.tar.gz.
File metadata
- Download URL: erbsland_sphinx_ansi-1.2.4.tar.gz
- Upload date:
- Size: 42.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a558b081fb5b4ecf0d69c5c55e73355de56cbdf639b1aec4e1e4a6292e0c7e0
|
|
| MD5 |
b198a0b8fdb65c6ab361d97f3f33a62b
|
|
| BLAKE2b-256 |
79657359acbf82e3796bfa1bb1f4ed89bf8289aaf569356c9584bc38fa9625ce
|
Provenance
The following attestation bundles were made for erbsland_sphinx_ansi-1.2.4.tar.gz:
Publisher:
publish.yml on erbsland-dev/erbsland-sphinx-ansi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
erbsland_sphinx_ansi-1.2.4.tar.gz -
Subject digest:
5a558b081fb5b4ecf0d69c5c55e73355de56cbdf639b1aec4e1e4a6292e0c7e0 - Sigstore transparency entry: 1776611274
- Sigstore integration time:
-
Permalink:
erbsland-dev/erbsland-sphinx-ansi@62861b6080db26d3e6c37d02b745b5795a37c0fe -
Branch / Tag:
refs/tags/v1.2.4 - Owner: https://github.com/erbsland-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@62861b6080db26d3e6c37d02b745b5795a37c0fe -
Trigger Event:
release
-
Statement type:
File details
Details for the file erbsland_sphinx_ansi-1.2.4-py3-none-any.whl.
File metadata
- Download URL: erbsland_sphinx_ansi-1.2.4-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7098dfb3941e60f0316b740f6fce0a737674c3010eb8939310748c26a60ddeaa
|
|
| MD5 |
bdba9467e96b91cf80fc3724f6bbbffc
|
|
| BLAKE2b-256 |
843e9bfe20b1630754e98b71e5b2b02c5e94a8ce3af2ead4cffe361494379e3a
|
Provenance
The following attestation bundles were made for erbsland_sphinx_ansi-1.2.4-py3-none-any.whl:
Publisher:
publish.yml on erbsland-dev/erbsland-sphinx-ansi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
erbsland_sphinx_ansi-1.2.4-py3-none-any.whl -
Subject digest:
7098dfb3941e60f0316b740f6fce0a737674c3010eb8939310748c26a60ddeaa - Sigstore transparency entry: 1776611427
- Sigstore integration time:
-
Permalink:
erbsland-dev/erbsland-sphinx-ansi@62861b6080db26d3e6c37d02b745b5795a37c0fe -
Branch / Tag:
refs/tags/v1.2.4 - Owner: https://github.com/erbsland-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@62861b6080db26d3e6c37d02b745b5795a37c0fe -
Trigger Event:
release
-
Statement type: