ansiscape
ansiscape is a Python package and CLI tool for creating and interpreting ANSI escape codes.
- Support for named, 8-bit and 24-bit colours.
- Create formatted strings with nested sequences and property reversions.
- Convert embedded escape codes into explanatory dictionaries.
- Write sequences as fully resolved strings and explanatory JSON.
Full documentation is published at ansiscape.readthedocs.io.
Installation
ansiscape requires Python 3.8 or later.
pip install ansiscape
Basic CLI usage
ansiscape on the command line will read from stdin and emit a JSON document describing the text and its escape codes.
For example:
ls --color | ansiscape
[{"background": -1, "foreground": 4, "weight": 1},"ansiscape",{"background": -1},"\n",{"foreground": 4, "weight": 1},"ansiscape.egg-info",{"background": -1},"\n",{"foreground": 2, "weight": 1},"build.sh",{"background": -1},"\ncoverage.xml\n",{"foreground": 4, "weight": 1},"dist",{"background": -1},"\n",{"foreground": 4, "weight": 1},"docs",{"background": -1},"\n",{"foreground": 4, "weight": 1},"htmlcov",{"background": -1},"\nLICENSE\n",{"foreground": 2, "weight": 1},"lint.sh",{"background": -1},"\nMANIFEST.in\nmkdocs.yml\nmypy.ini\nPipfile\nPipfile.lock\npyproject.toml\nREADME.md\nsetup.py\n",{"foreground": 2, "weight": 1},"test-cli.sh",{"background": -1},"\n",{"foreground": 4, "weight": 1},"tests",{"background": -1},"\n",{"foreground": 2, "weight": 1},"test.sh",{"background": -1}]
Full documentation is published at ansiscape.readthedocs.io.
Basic Python usage
ansiscape provides a library of functions for formatting text.
For example, to make text bold:
from ansiscape import heavy
print(heavy("Hello, world!"))
[1mHello, world![22m
These functions can be nested to create complex formatted strings. Specific instructions can also be embedded:
from ansiscape import Interpretation, Sequence, heavy
from ansiscape.enums import MetaInterpretation, Weight
sequence = Sequence(
Interpretation(weight=Weight.HEAVY),
"Hello, world!",
Interpretation(weight=MetaInterpretation.REVERT),
)
print(sequence)
[1mHello, world![22m
Full documentation is published at ansiscape.readthedocs.io.
👋 Hello!
Hello! I'm Cariad Eccleston and I'm an independent/freelance software engineer. If my work has value to you, please consider sponsoring.
If you ever raise a bug, request a feature or ask a question then mention that you're a sponsor and I'll respond as a priority. Thank you!
Metadata
Release files for ansiscape 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ansiscape-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / ansiscape-1.2.0-py3-none-any.whl
| Download URL | ansiscape-1.2.0-py3-none-any.whl |
|---|---|
| Size | 32.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7fb034f6ae40ca7d0ff2d45854be51fc2d280037b1aa65cc0141ae2693b6ca46
|
|
BLAKE2b-256 checksum How to use checksums |
a86a19a8b6af85d2a502d48d2e56882f9d5ff6e398785fb41b445cebdf8638ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.20
|
Security for ansiscape 1.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.