stransi 🖍️
I see a
\033[1;31mred\033[;39mdoor, and I want it painted\033[1;30mblack\033[;39m.
stransi is a lightweight parser for ANSI escape code sequences. It implements a string-like type that is aware of its own ANSI escape sequences, and can be used to parse most of the common escape sequences used in terminal output manipulation.
Features
- ✨ Good support of ANSI escape sequences
- 🎨 Focus on coloring and styling
- 🛡️ Unsupported
CSIescape sequences are emitted as tokens - 🏜️ Only one dependency: ochre
- 🐍 Python 3.8+
Installation
$ pip install stransi
Usage
In [1]: from stransi import Ansi
In [2]: text = Ansi(
...: "I see a \033[1;31mred\033[;39m door, "
...: "and I want it painted \033[1;30mblack\033[;39m"
...: )
In [3]: list(text.escapes())
Out[3]:
['I see a ',
Escape('\x1b[1;31m'),
'red',
Escape('\x1b[;39m'),
' door, and I want it painted ',
Escape('\x1b[1;30m'),
'black',
Escape('\x1b[;39m')]
In [4]: list(text.instructions())
Out[4]:
['I see a ',
SetAttribute(attribute=<Attribute.BOLD: 1>),
SetColor(role=<ColorRole.FOREGROUND: 30>, color=Ansi256(1)),
'red',
SetAttribute(attribute=<Attribute.NORMAL: 0>),
SetColor(role=<ColorRole.FOREGROUND: 30>, color=None),
' door, and I want it painted ',
SetAttribute(attribute=<Attribute.BOLD: 1>),
SetColor(role=<ColorRole.FOREGROUND: 30>, color=Ansi256(0)),
'black',
SetAttribute(attribute=<Attribute.NORMAL: 0>),
SetColor(role=<ColorRole.FOREGROUND: 30>, color=None)]
Credits
Photo by Tien Vu Ngoc on Unsplash.
Metadata
Release files for stransi 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stransi-0.3.0.tar.gz | 8.4 kB | Without provenance | Details for stransi-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stransi-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for stransi-0.3.0-py3-none-any.whl |
Total release size: 18.0 kB
Release files / stransi-0.3.0.tar.gz
| Download URL | stransi-0.3.0.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ba0195f935a8a152ad1921b25e14e7e78c549948d2ef0f63a6a5d9ab4625830
|
|
BLAKE2b-256 checksum How to use checksums |
fe96d72e9fd64f11502e37ec397a912bba4a81cbe195a07e0cd4d5b5a6268de7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.9.7 Linux/5.13.0-22-generic
|
Release files / stransi-0.3.0-py3-none-any.whl
| Download URL | stransi-0.3.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7082fe969abca1059437a45b81c3b05a2eb1362503487bd35bd1d8919af3f0a4
|
|
BLAKE2b-256 checksum How to use checksums |
fa1071eff1dc5f6e97b1d245c9efb96cc7e581340fe6218bb4744e0e2f130859
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.9.7 Linux/5.13.0-22-generic
|
Security for stransi 0.3.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.