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.2.0.tar.gz (6.1 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.2.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_ansi_style-0.2.0.tar.gz
Algorithm Hash digest
SHA256 79dbf5db52dca3033a0d40eaf197aae6b069d843cc80bac10083333365a2682d
MD5 abbb5fa58b385dba36cc643e7066d6c7
BLAKE2b-256 c79c8c4dd189df3f9ba8cb5e7a90a6371026ffbc3cdb27e0fe378f99cee7b5a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_ansi_style-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d362f39df5ecfec437088d6533cdbe5e9826fefa66454f984795dec5f2acd0a
MD5 6744fdd6b7c3a1f64a82542987c435e1
BLAKE2b-256 4510d5713fff60ca15e73f6259b432309beceb7ea7d03befa22c4059365369f3

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