Skip to content

ANSI escape codes for styling strings in the terminal

Notifications You must be signed in to change notification settings

shawwn/ansi-styles-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ansi-styles

ANSI escape codes for styling strings in the terminal

A port of the Node.js package ansi-styles to Python.

Install

python3 -m pip install -U ansi-styles

Usage

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.

About

ANSI escape codes for styling strings in the terminal

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages