Convert any color in RGB or hexadecimal format to ANSI code
Project description
ANSI Converter
Convert any colour to the ANSI format to write in colours in your terminal.
Installation
Run this command to install ansiconverter
:
python -m pip install -U ansiconverter
To install for development:
git clone https://github.com/thomassamoth/ansiconverter.git
cd ansiconverter
pip install -e .[dev]
:computer: Usage
:arrow_right: Converter module
Convert any RGB colour to ANSI
# How to print a green text on a white background
from ansiconverter.converter import RGBtoANSI
print(RGBtoANSI(text='Green text on a white background',foregound=[0, 255, 0], background=[255, 255, 255]))
Result:
Convert any hexadecimal colour to ANSI
Warning
Some colour combinations are incompatible, and the result will be slightly different from what is expected.
# How to print a yellow text on a navy blue background, with hexadecimal values.
from ansiconverter.converter import HEXtoANSI
print(HEXtoANSI('Some yellow text on blue background','#fdf31f', '000080'))
Result:
:art: Styles module
Write your text in different styles:
- bold
- italic
- faint
- underlined
- bold & underlined
- strikethrough
- reversed
from ansiconverter.styles import styles
print(styles.bold("Some text in bold"))
Combination of colours and styles
It is possible to combine text styles with colours by doing so:
from ansiconverter.converter import *
from ansiconverter.styles import styles
print(styles.bold(HEXtoANSI('A yellow text in bold','#f6cf6c')))
Result:
You can replace styles.bold()
by any function mentionned above i.e. styles.italic()
. You can even combine different styles!
:heavy_plus_sign: 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-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 366f8b3e73ea95cce52ff4b91c8393dedc502a95ded90d32921345d6011eac07 |
|
MD5 | 66617a30369d478fe0e79022f42ac6d4 |
|
BLAKE2b-256 | 862f858bd0fc5119ad2c202ce18ec493e04855a5c1d3472f1f7d252a5cc88fbd |