Skip to main content

PyPI Python package PyPI - License

stransi 🖍️

stransi

I see a \033[1;31mred\033[;39m door, 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

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.

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)

Source distribution for stransi 0.3.0
File Size Uploaded
stransi-0.3.0.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stransi 0.3.0
File Interpreter ABI Platform
stransi-0.3.0-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page