Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/getcuia/stransi
🖍️ A lightweight Python parser library for ANSI escape code sequences
https://github.com/getcuia/stransi
ansi ansi-colors ansi-escape-codes console cuia parser python stransi terminal
Last synced: about 2 months ago
JSON representation
🖍️ A lightweight Python parser library for ANSI escape code sequences
- Host: GitHub
- URL: https://github.com/getcuia/stransi
- Owner: getcuia
- License: mit
- Created: 2021-11-15T22:08:51.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-08T23:01:51.000Z (almost 2 years ago)
- Last Synced: 2024-10-08T01:45:16.639Z (4 months ago)
- Topics: ansi, ansi-colors, ansi-escape-codes, console, cuia, parser, python, stransi, terminal
- Language: Python
- Homepage: https://pypi.org/project/stransi/
- Size: 370 KB
- Stars: 17
- Watchers: 2
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![PyPI](https://img.shields.io/pypi/v/stransi)](https://pypi.org/project/stransi/)
[![Python package](https://github.com/getcuia/stransi/actions/workflows/python-package.yml/badge.svg)](https://github.com/getcuia/stransi/actions/workflows/python-package.yml)
[![PyPI - License](https://img.shields.io/pypi/l/stransi)](https://github.com/getcuia/stransi/blob/main/LICENSE)# [stransi](https://github.com/getcuia/stransi#readme) 🖍️
> I see a `\033[1;31m`red`\033[;39m` door, and I want it painted
> `\033[1;30m`black`\033[;39m`.stransi is a lightweight parser for
[ANSI escape code sequences](https://en.wikipedia.org/wiki/ANSI_escape_code). 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](FEATURES.md)
- 🎨 Focus on coloring and styling
- 🛡️ Unsupported `CSI` escape sequences are emitted as tokens
- 🏜️ Only one dependency: [ochre](https://github.com/getcuia/ochre)
- 🐍 Python 3.8+## Installation
```console
$ pip install stransi
```## Usage
```python
In [1]: from stransi import AnsiIn [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=),
SetColor(role=, color=Ansi256(1)),
'red',
SetAttribute(attribute=),
SetColor(role=, color=None),
' door, and I want it painted ',
SetAttribute(attribute=),
SetColor(role=, color=Ansi256(0)),
'black',
SetAttribute(attribute=),
SetColor(role=, color=None)]
```## Credits
[Photo](https://github.com/getcuia/stransi/raw/main/banner.jpg) by
[Tien Vu Ngoc](https://unsplash.com/@tienvn3012?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)
on
[Unsplash](https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText).