A port of the Node.js package `ansi-styles` to Python
Project description
ansi-styles
A port of the Node.js package ansi-styles
to Python.
Quickstart
python3 -m pip install -U ansi-styles
(That strange-looking setup command is because I've found it to be the most reliable. The pip
command often aliases to python 2, and pip3
often installs to the wrong Python package directory.)
Once it's installed, you can do this:
from ansi_styles import ansiStyles as styles
print(f'{styles.green.open}Hello world!{styles.green.close}')
# Color conversion between 256/truecolor
# NOTE: When converting from truecolor to 256 colors, the original color
# may be degraded to fit the new color palette. This means terminals
# that do not support 16 million colors will best-match the
# original color.
print(f'{styles.color.ansi(styles.rgbToAnsi(199, 20, 250))}Hello World{styles.color.close}')
print(f'{styles.color.ansi256(styles.rgbToAnsi256(199, 20, 250))}Hello World{styles.color.close}')
print(f'{styles.color.ansi16m(*styles.hexToRgb("#abcdef"))}Hello World{styles.color.close}')
License
MIT
Contact
A library by Shawn Presser. If you found it useful, please consider joining my patreon!
My Twitter DMs are always open; you should send me one! It's the best way to reach me, and I'm always happy to hear from you.
- Twitter: @theshawwn
- Patreon: https://www.patreon.com/shawwn
- HN: sillysaurusx
- Website: shawwn.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ansi-styles-0.2.1.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for ansi_styles-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 452cf9e1138a4d7cdb11ceb57418aaac5ba05fdd0e4625697bb5b3381c0772ad |
|
MD5 | 7ae76eabb3f09fba81569e114e02e2af |
|
BLAKE2b-256 | 45227de471aa2c662e9039c040011b385d0dd506ecceff452c4114201d27bd01 |