Convert any color in RGB or hexadecimal format to ANSI code
Reason this release was yanked:
It was missing the python file in the build and therefore it is unusable as a package.
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
Built Distribution
Hashes for ansiconverter-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58a08875125b7c6ace138d5137be124aff3a311984e578287a86c40d8eb2b938 |
|
MD5 | c05dd3ae41abdbe08e5dd795532dcbae |
|
BLAKE2b-256 | 54b31f13de0d0d2dda598732165e2c5646b64429bb0cc24afadacf3848f43659 |