Skip to main content

Python Libary to print colored and styled text in terminal. Offers color-specific configuration by providing 24bit hex or RGB values as well 256-color mode.

Project description

Moecolor (Flexible terminal text coloring and styling)

Table of Contents

Overview

This lightweight tool allows you to color terminal text and style it based on predefined attributes. The tool works very much like the print function. Except it is a fancier print that you can do a lot more with to control text color and style.

Library Installalion

To install the library simply run the following command in a cmd, shell or whatever...

# It's recommended to create a virtual environment

# Windows
pip install moecolor

# Linux
pip3 install moecolor

Library usage?

Example usage

The following examples shows how to print text in green in so many different ways:

from moecolor import print
print('My example text as green', color='green')
print('My example text as green', color='grreenn') # This is obviously not green, but we got you.
print('My example text as green', color='#00FF00')
print('My example text as green', color=(0, 255, 0))
print('My example text as green', color=(10,))
print('My example text as green', color=10)

The following example shows how to underline, cross-out, bold, italize, a red text:

from moecolor import print
print('My example text as green', color='red', attr=['bold', 'italic', 'strike', 'underline'])

Do you want more fine-grained control over your text? Sure, the following example prints per word coloring. It will print RED GREEN BLUE TEXT, using various colour configurations.

from moecolor import print # This is an optional import, you can still use the original print function.
from moecolor import FormatText as ft
print("{} {} {}".format(ft('RED TEXT', color='#ff0000'), ft('GREEN TEXT', color='green'), ft('BLUE TEXT', color=12)))

Usage Guidelines

The tool simply overloads the print function, so you can use it as a normal print and if you'd like to color and style text you can provide extra arguments. The tool accepts the following arguments in addition to the kwargs accepted by the builtin print function.

  • color
  • attr
  • usage

There are many options to choose from to color your text. You can:

  • Choose a color string from a list of pre-defined colors ['BLACK', 'RED', 'GREEN', 'YELLOW', 'BLUE', 'MAGENTA', 'CYAN', 'BRIGHT_GRAY', 'DEFAULT', 'DARK_GRAY', 'BRIGHT_RED', 'BRIGHT_GREEN', 'BRIGHT_YELLOW', 'BRIGHT_BLUE', 'BRIGHT_MAGENTA', 'BRIGHT_CYAN','WHITE', 'PURPLE', 'VOILET', 'LIME', 'ORANGE', 'RANDOM']
  • If you wish to generate a random color, you can supply the word: 'RANDOM'.
  • If you wish to pick a color from 256-color mode scale based on https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit, you can provide an integer between [0-255]
  • If you wish to provide an RGB value for a specific 24-bit color, you provide a tuple/list of RGB values: (R, G, B) and numbers must be integers between [0-255]
  • If you wish to provide a hex-code for an 24-bit RGB equivelent color, you can provide a string like #FFFFFF.

To style your text, you can use a set of pre-defined attributes:

  • 'BOLD': bold text (synonymous options: 'b', 'bold', 'thick')
  • 'DIM': dim text a little (synonymous options: 'dim', 'dark', 'd')
  • 'ITALIC': italize text (synonymous options: 'i', 'italic')
  • 'UNDERLINE': underline text, (synonymous options: 'u', 'underline')
  • 'BLINK': make text blink at less than 150 times per minute (synonymous options: 'blink', 'blinking', 'flash')
  • 'INVERT': invert text (synonymous options: 'reverse', 'invert', 'switch')
  • 'HIDE': hide text from terminal (synonymous options: 'conceal', 'hide', 'invisible')
  • 'STRIKE': make text crossed-out, (synonymous options: 'crossed-out', 'cross-out', 'crossed-out', 'strike', 's')
  • 'DOUBLE-UNDERLINE': underline text with double lines, (synonymous options: 'double-underline', '2u', 'uu', 'du')
  • 'FOREGROUND': control foreground color [default behavior], (synonymous options: 'foreground', 'fg', 'fore-ground')
  • 'BACKGROUND': control background color [to apply color the background instead of the foreground], (synonymous options: 'background' ,'bg', 'back-ground')
  • 'OVERLINED': overline text (synonymous options: 'overlined', 'o', 'over-lined')
  • 'UNDERLINE-COLOR': apply color to underlined text, used along with underlining, otherwise no effect (synonymous options: underline-color', 'ucolor', 'u-color', 'uc')
  • 'CLEAR': clear screen, then print text. (synonymous options: 'reset', 'reset-position', 'clear', 'clear-screen')

To show tool usage, or this README, i.e., you supply the keyword usage or one of its synonymous ('h', 'usage', 'show_help', 'help_me', 'use') as follows:

print(usage=True)

You can also display tool usage/docs using the following command:

help(print)

REMARKS

# Note, all strings are case insensitive, so don't worry. Not just that, even if you misspell a color,
# we will guess it for you ;), just do NOT type `regrlue` and expect it to be blue for example,
# it might come up as green though.

"""
Some attributes may not be supported in all terminals. So, if a specific attribute does not work, that means the
terminal you are using does not support it.

Windows terminals (CMD, PS) support most of attributes, but the following ['blink', 'dim']
LINUX terminals support all AFAIK
"""

Author: Hamdan, Muhammad (@mhamdan91 - آ©)

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

moecolor-1.0.0rc1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moecolor-1.0.0rc1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file moecolor-1.0.0rc1.tar.gz.

File metadata

  • Download URL: moecolor-1.0.0rc1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.7

File hashes

Hashes for moecolor-1.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 d83a0836a565b6db63c6c9c78529864b0fa24e75b5a6d967816b90416421ba14
MD5 4ee76eec7f7c85654e15eef1ad1f3e42
BLAKE2b-256 2f40b9a86e9edb7cbc5307fb27d11cf27d14f5fade89e7c3614a82638c499689

See more details on using hashes here.

File details

Details for the file moecolor-1.0.0rc1-py3-none-any.whl.

File metadata

  • Download URL: moecolor-1.0.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.7

File hashes

Hashes for moecolor-1.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 8f97496fd6bda6190ebd2ec58e76505ff6befb4b827f2bbb2e81e7624f6037f4
MD5 e92bcec7e4da47157be712e4a2323cf0
BLAKE2b-256 509e7cdc2c9aa3c84dffcbd64fa638d5a976b7a10b2cf155fb8606fc2f924d33

See more details on using hashes here.

Supported by

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