Convert any color in RGB or hexadecimal format to ANSI code
Project description
ansiconverter
Convert any color to the ANSI format to write in colors in your terminal.
Installation
Run this command to install ansiconverter:
pip install ansiconverter
Usage
Converter module
Convert any RGB color to ANSI
# How to print a green text on a white background
from ansiconverter import converter as cv
print(f"{cv.RGBtoANSI(foregound=[0, 255, 0], background=[255, 255, 255])}Green text on white background{cv.RESET}")
# Alternative
duo = cv.RGBtoANSI(foregound=[0, 255, 0], background=[255, 255, 255])
print(f"{duo} Another green text on white bg {cv.RESET}")
Convert any hexadecimal color to ANSI
Warning: no background color available for now
# How to print a yellow text with its hexadeciaml value
from ansiconverter import converter as cv
print(f"{cv.HEXtoANSI('#f6cf6c')}Some yellow text{cv.RESET}")
Styles module
Write your text in different styles :
- bold
- italic
- faint
- underlined
- bold & underlined
- strikethrough
- reversed
from ansiconverter import styles
print(styles.bold("Some text in bold"))
Combination of colors and styles
It is possible to combine text styles with colors by doing so:
from ansiconverter import converter, styles
yellow = converter.HEXtoANSI('#f6cf6c')
print(styles.bold(yellow)+"Some yellow text in bold"+RESET)
You can replace styles.bold()
by any function mentionned above i.e. styles.italic()
.
Additional features
You can also use RGB to HEX converter or HEX to RGB by themselves like this:
>>>from ansiconverter import converter
>>> print(converter.HEXtoRGB("#0b38c1"))
[11, 59, 193])
>>> print(converter.RGBtoHEX([11, 59, 193]))
"#0b3bc1"
Note: This repository is based on Mark Smith's talk available here and its linked repository
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
ansiconverter-0.0.2.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for ansiconverter-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f6543bca9696105786dc6a09fd1250b3b0f2e9ed9983f180ee8255c8a5c8196 |
|
MD5 | c519501c78c4d34228261522be6ad39c |
|
BLAKE2b-256 | 1cb0e0991a16a92a4b21cef771e17d68d23e92949977d6bb9872d57750fad7c6 |