Skip to main content

Terminal text styling with zero dependencies and TTY detection.

Project description

philiprehberger-ansi-style

Tests PyPI version Last updated

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:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

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

philiprehberger_ansi_style-0.1.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_ansi_style-0.1.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_ansi_style-0.1.2.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_ansi_style-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6ea5748adaee36c441be6bd460cc368222016018b4abbb13db9745be279dc72f
MD5 e9177d9165e04c391f174d843c7836e9
BLAKE2b-256 1c906478999dca20734c7eb7966718fd201924fda46b73bf01893de5018232f8

See more details on using hashes here.

File details

Details for the file philiprehberger_ansi_style-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_ansi_style-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b36267740ea9cc2b17155bfa6fca295623c910d5e3cb23dc8626e5ea6a957d74
MD5 52627ad3e78a4a066f1db20c360ed616
BLAKE2b-256 3e966a8af9e0ed42f6881d97a3d9d9b2e796b8eeaf50693e8b5e06c830254016

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page