Adds colors to your console prints.
Project description
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!
[94mHello World![0m
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:
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!
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
File details
Details for the file ColorfulOutput-0.0.1.tar.gz
.
File metadata
- Download URL: ColorfulOutput-0.0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5732e484e26b2d8f1b7310c9f0552ab69d64f8131998564cfe224938f56e0b9f |
|
MD5 | c78582233f63f9c7fd95f96244d62861 |
|
BLAKE2b-256 | c50d9f93088d9aface3de206b5d72abf81bbc37f8887d62fa82dd6d172e1f37d |
File details
Details for the file ColorfulOutput-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: ColorfulOutput-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a8bda039ce5ed653ccabd4bcfbd6701c0a8d4261be305880b997154b373f699 |
|
MD5 | 6ecba451dc10ebbc45a56a3b2d293a6b |
|
BLAKE2b-256 | b374fa86c125b1fa182375e95a46e44a7dd149978e77ecdebd73912eeffcaaf3 |