Create and interpret ANSI escape codes
Project description
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
["ansiscape\nbuild.sh\ncoverage.xml\ndocs\nhtmlcov\nLICENSE\nlint.sh\nMANIFEST.in\nmkdocs.yml\nmypy.ini\nPipfile\nPipfile.lock\npyproject.toml\nREADME.md\nsetup.py\ntest-cli.sh\ntests\ntest.sh"]
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!
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 Distributions
Built Distribution
File details
Details for the file ansiscape-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: ansiscape-1.1.2-py3-none-any.whl
- Upload date:
- Size: 32.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b64c4cb667b3adcd2a921dcdaa36520f0c2c544304c3c56b25f3b2329e2682e |
|
MD5 | 6c022c179a8cfe53804a8c832fc133cd |
|
BLAKE2b-256 | 6c27aa1cd6f041f2057c382dedae4cbf4c7c143512fb6961eeb3e7445c092511 |