https://github.com/cariad/ansiscape
Python package and CLI tool for creating and interpreting ANSI escape codes
https://github.com/cariad/ansiscape
ansi cli-app color formatting python python-package python3
Last synced: 4 months ago
JSON representation
Python package and CLI tool for creating and interpreting ANSI escape codes
- Host: GitHub
- URL: https://github.com/cariad/ansiscape
- Owner: cariad
- License: mit
- Created: 2021-09-05T12:32:09.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-08T03:46:19.000Z (over 3 years ago)
- Last Synced: 2025-02-12T23:41:29.303Z (over 1 year ago)
- Topics: ansi, cli-app, color, formatting, python, python-package, python3
- Language: Python
- Homepage: https://ansiscape.readthedocs.io/
- Size: 265 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# ansiscape
[](https://circleci.com/gh/cariad/ansiscape/tree/main) [](https://codecov.io/gh/cariad/ansiscape) [](https://ansiscape.readthedocs.io/en/latest/?badge=latest)
`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](https://ansiscape.readthedocs.io).
## Installation
`ansiscape` requires **Python 3.8 or later**.
```bash
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:
```bash
ls --color | ansiscape
```
```text
[{"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](https://ansiscape.readthedocs.io).
## Basic Python usage
`ansiscape` provides a library of functions for formatting text.
For example, to make text bold:
```python
from ansiscape import heavy
print(heavy("Hello, world!"))
```
```text
[1mHello, world.
## 👋 Hello!
**Hello!** I'm [Cariad Eccleston](https://cariad.io) and I'm an independent/freelance software engineer. If my work has value to you, please consider [sponsoring](https://github.com/sponsors/cariad/).
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!