Terminal text styling with zero dependencies and TTY detection.
Project description
philiprehberger-ansi-style
Terminal text styling with zero dependencies and TTY detection.
Installation
pip install philiprehberger-ansi-style
Usage
from philiprehberger_ansi_style import red, green, blue, bold, underline
print(red("Error: something went wrong"))
print(green("Success!"))
print(bold(blue("Important message")))
Color functions
from philiprehberger_ansi_style import (
red, green, blue, yellow, cyan, magenta, white, gray,
)
print(red("Red text"))
print(green("Green text"))
print(blue("Blue text"))
print(yellow("Yellow text"))
print(cyan("Cyan text"))
print(magenta("Magenta text"))
print(white("White text"))
print(gray("Gray text"))
Style functions
from philiprehberger_ansi_style import bold, dim, underline, italic
print(bold("Bold text"))
print(dim("Dim text"))
print(underline("Underlined text"))
print(italic("Italic text"))
Custom styling
from philiprehberger_ansi_style import style
print(style("Alert", fg="red", bold=True))
print(style("Note", fg="cyan", underline=True))
print(style("Highlight", fg="white", bg="blue", bold=True))
Strip ANSI codes
from philiprehberger_ansi_style import red, strip_ansi
styled = red("hello")
plain = strip_ansi(styled) # "hello"
API
| Function | Description |
|---|---|
red(text) |
Apply red foreground color |
green(text) |
Apply green foreground color |
blue(text) |
Apply blue foreground color |
yellow(text) |
Apply yellow foreground color |
cyan(text) |
Apply cyan foreground color |
magenta(text) |
Apply magenta foreground color |
white(text) |
Apply white foreground color |
gray(text) |
Apply gray foreground color |
bold(text) |
Apply bold weight |
dim(text) |
Apply dim intensity |
underline(text) |
Apply underline decoration |
italic(text) |
Apply italic style |
style(text, *, fg, bg, bold, dim, underline) |
Apply custom combination of colors and styles |
strip_ansi(text) |
Remove all ANSI escape codes from text |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_ansi_style-0.2.0.tar.gz.
File metadata
- Download URL: philiprehberger_ansi_style-0.2.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79dbf5db52dca3033a0d40eaf197aae6b069d843cc80bac10083333365a2682d
|
|
| MD5 |
abbb5fa58b385dba36cc643e7066d6c7
|
|
| BLAKE2b-256 |
c79c8c4dd189df3f9ba8cb5e7a90a6371026ffbc3cdb27e0fe378f99cee7b5a8
|
File details
Details for the file philiprehberger_ansi_style-0.2.0-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_ansi_style-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d362f39df5ecfec437088d6533cdbe5e9826fefa66454f984795dec5f2acd0a
|
|
| MD5 |
6744fdd6b7c3a1f64a82542987c435e1
|
|
| BLAKE2b-256 |
4510d5713fff60ca15e73f6259b432309beceb7ea7d03befa22c4059365369f3
|