Skip to main content

VividHues: super lite package for colored strings in Python!

Project description

VividHues :rainbow: :package:

VividHues Downloads Downloads Downloads

CodeFactor Latest SemVer Repo Size Total Lines

VividHues:    super lite package for colored strings in Python!


:hammer_and_wrench: Official Installation

Pop this command in your shell/terminal to install VividHues.
# in your shell/terminal...
$ pip install VividHues
Stick this wherever you need VividHues!
# at the top of your .py files...
from VividHues import Clr

:bricks: Dependency

requirements.txt (Highly Recommended!)

Append the following to your Python packages requirements.txt.
VividHues>=5.2.0
Changelog:
VividHues==3.0.0    #  only has Clr codes
VividHues>=4.1.0    #  adds abbreviations & Magic Functions
VividHues>=5.2.0    #  adds Magic Function Clr.pattern()
VividHues>=5.3.0    #  all Magic Functions no longer leak color

.github/Dependabot.yml (optional, but needs requirements.txt)

First, if you don't already have a .github directory, create one.
Then, add a Dependabot.yml file to it.
version: 2
updates:
  - package-ecosystem: "pip"
    directory: "/"
    schedule:
      interval: "daily"

Dockerfile :whale: (optional)

You can use this if you have a Docker container.
# recommended
COPY requirements.txt .
RUN pip install -r requirements.txt
# alternatively...
RUN pip install VividHues

:snake: Python Example

print(Clr.BO + Clr.UL + Clr.rainbow('I love VividHues!') + Clr.RS)
print(f"{Clr.RED}It's got my fave color!{Clr.RS}")
print(f"Soooo {Clr.jazzy('jazzy') + Clr.RS}")
#                          ^^^
# you'll get an error using "" in f-string interpolations
print(Clr.pattern("Kenny Oliver", Clr.PURPLE, Clr.CYAN, Clr.LIME) + Clr.RS)

:warning: Preventing Color Leakage!

What is color leakage??? :thinking:

Color leakage is when you have forgotten to use Clr.RS/Clr.RESET to reset the formatting after the last character printed to the standard output!

It results in any trailing characters, in the output stream, to continue to have the same formatting.

This is an intentional feature, because it allows for the formatting of entire chunks of code in one go. See the example

:pencil: Note!

As of VividHues>=5.3.0, ALL magic functions do not leak color.

Previously, it was only Clr.random()!

How do I prevent/solve this? :tada:

:a: End print() with Clr.RS/Clr.RESET

print(... + Clr.RS)  # recommended!

print(..., Clr.RS)

print(..., end=Clr.RS+"\n")

:b: Format chunks of code

# start formatting here
print(Clr.BOLD + Clr.RED, end="")


if something:
  print(Clr.BLUE + "blah blah blah" + Clr.RS)
else:
  for x in range(100):
    # lots of print statements


# end formatting here
print(Clr.RS, end="")

:bulb: Tip!

These solutions also prevent the leakage of other formatting

(e.g. Clr.BO, Clr.BOLD, Clr.UL, Clr.UNDERLINE)


:rainbow: Available Clr codes:

Just put a code in the gap Clr.___

Clr:                  RED, ORANGE, YELLOW, LIME, GREEN, BLUE, CYAN, PURPLE, PINK, BLACK, WHITE
Formatter:    UNDERLINE, UL, BOLD, BO
Reset:             RESET, RS
NOTE:
This depends on what you imported VividHues as...

from VividHues import Clr


:magic_wand: Magic Functions

:bulb: TIP!    Magic Functions do not leak color

:game_die: Clr.random()

print(Clr.random(string))
Paints your string in a random Clr code.

:saxophone: Clr.jazzy()

print(Clr.jazzy(string))
Paints each letter in jazzy random colors! It's a total gamble, that's guaranteed to be ugly! :)

:rainbow: Clr.rainbow()

print(Clr.rainbow(string))
Paints your string in a rainbow pattern.

:test_tube: Clr.pattern()

print(Clr.pattern(string, *color))
Paint your letters in a repeating pattern, by specifying an unlimited amount of Clr codes!

:muscle: How VividHues stacks up...

Feature VividHues Colorama termcolor
Simplicity/Abstraction :star: :star: :star:
Font Colors :star: :star: :star:
Background/Highlight :crossed_fingers: :star: :star:
Bold/Underline :star: :star:
Lightweight :star:
Auto-Reset :crossed_fingers: :star:
Cursor-Positioning :star:
Special Features :star: :star:
Total 5/8 + 2/8 = 7/8 5/8 5/8

Potentially, VividHues will have more features than the alternatives if they are implemented.


Kenny Oliver ©2021

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

VividHues-5.3.7.tar.gz (17.2 kB view hashes)

Uploaded Source

Built Distribution

VividHues-5.3.7-py3-none-any.whl (17.1 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