Skip to main content

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


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.1.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

ansiconverter-0.0.1-py3-none-any.whl (3.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page