Skip to main content

ColorfulOutput

A python library that adds colors to your console prints.

Author

Installation

pip install ColorfulOutput
# or
pip3 install ColorfulOutput

Usage

The library contains methods that you can use to color your console text.
These "colored" strings should only be used for console prints, and not for anything else!

import ColorfulOutput as cc

text = cc.HEADER("Hello World!")
print(text)
from ColorfulOutput import BLUE, RED

print(BLUE("This is all blue text!"))
print(RED("This is all red text!"))
from ColorfulOutput import CYAN, YELLOW, RED, BOLD, UNDERLINE

text = f'{BOLD("Never")} {YELLOW("gonna")} {UNDERLINE("give")} {RED("you")} {CYAN("up")}!'

print(text)

Methods

  • HEADER(text)
  • BLUE(text)
  • CYAN(text)
  • GREEN(text)
  • YELLOW(text)
  • RED(text)
  • BOLD(text)
  • UNDERLINE(text)

Known issues!

Repr

The methods will return a text string that seems like a normal text to the console, but it is actually a string with special characters that makes the text colored. This means that when you use the repr() function, it will return a string with special characters instead of the actual text.

This also means that when you use the !r format specifier, it will return a string with special characters instead of the actual text.

from ColorfulOutput import BLUE

clean_text = "Hello World!"
color_text = BLUE(clean_text)

print(repr(clean_text))
# Output: 'Hello World!'

print(f'{clean_text!r}')
# Output: 'Hello World!'

print(repr(color_text))
# Output: '\x1b[94mHello World!\x1b[0m'

print(f'{color_text!r}')
# Output: '\x1b[94mHello World!\x1b[0m'

Writing to files

When you write the colored text to a file, it will write the special characters to the file instead of the actual text.

from ColorfulOutput import BLUE

clean_text = "Hello World!"
color_text = BLUE(clean_text)

with open("file.txt", "w") as file:
    file.write(clean_text)
    file.write(color_text)

file.txt:

Hello World!
Hello World!

Length

The special characters will also be counted as characters when you use the len() function.

from ColorfulOutput import BLUE

clean_text = "Hello World!"
color_text = BLUE(clean_text)

print(len(clean_text))
# Output: 12

print(len(color_text))
# Output: 21

Adding multiple colors and styles

When you add multiple colors and styles to a string, it will not work as expected.

from ColorfulOutput import BLUE, BOLD, UNDERLINE

text = BLUE("Hello ")
text += BOLD("World!")

full_text = UNDERLINE(text)

print(full_text)

Console output:
Console output

Workarounds

The only workaround for most of these issues is to create a "clean" string that only contains the text (as shown in the examples above).
Then a separate "color" string that contains the text with the colors and styles.

Future

All of these issues will be fixed in the future, but for now, you will have to use the workarounds.

If you any suggestions or issues, please let me know!

Metadata

Release files for ColorfulOutput 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ColorfulOutput 0.0.1
File Size Uploaded
ColorfulOutput-0.0.1.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ColorfulOutput 0.0.1
File Interpreter ABI Platform
ColorfulOutput-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.2 kB

Release files / ColorfulOutput-0.0.1.tar.gz

Download URL ColorfulOutput-0.0.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5732e484e26b2d8f1b7310c9f0552ab69d64f8131998564cfe224938f56e0b9f
BLAKE2b-256 checksum
How to use checksums
c50d9f93088d9aface3de206b5d72abf81bbc37f8887d62fa82dd6d172e1f37d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release files / ColorfulOutput-0.0.1-py3-none-any.whl

Download URL ColorfulOutput-0.0.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a8bda039ce5ed653ccabd4bcfbd6701c0a8d4261be305880b997154b373f699
BLAKE2b-256 checksum
How to use checksums
b374fa86c125b1fa182375e95a46e44a7dd149978e77ecdebd73912eeffcaaf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page