Allows colored output to the console
Project description
color_console_py
Small tool that enables you to write to the console in color using context mangers or f-strings.
It uses ANSI codes to color the console.
How to use
Getting a color
Creating a color requires style
, color
and background
, all of which can be called as positional or keyword arguments.
If not specified they will default to the console's default.
Colors can also be called as attributes of Color
or strings:
Color.black
=0
Color.red
=1
Color.green
=2
Color.yellow
=3
Color.blue
=4
Color.pink
=5
Color.brown
=6
Color.white
=7
Possible ways to call:
from color_console import Color
Color(1, 2, 3) # resulting color will be in style 1, color green, background yellow
Color() # resulting color will in default style, default color, default background
Color(1, "black", "white") #resulting color will be in style 1, color black, background white
Color(color=Color.red) # resulting color will be in default style, color red, default background
There are also some color presets like error
/err
, success
/succ
, warning
/warn
, info
,
that can be called with the positional keyword name
or as an attribute of Color
.
In this you can also define your own colors:
from color_console import Color
Color(name="error") # resulting color will be style 1, color red, background black
Color.info # resulting color will be style 1, color blue, default background
Color.test = Color(1, Color.pink, Color.brown) # color saved
Color.test # resulting color will be style 1, color pink, background brown
Using a color
Using a color can be done by printing it directly or using context managers:
Simple example:
from color_console import Color
col1 = Color(1, 2, 3) # get your color
print(col1.start()) # changes your console to the desired color/style
print("This is in color/style specified by col1")
col2 = Color(4, 5, 6) # get your color, no need to reset before
print(col2.start())
print("This is in color/style specified by col2")
print(col2.stop()) # resets the color
Better example using implicit conversion to str in f-strings:
from color_console import Color
print(f"{Color(1, 2, 3)}This is in the first color, {Color(4, 5, 6)} This is in the second color, {Color.end} This is in the default color")
Using context managers:
from color_console import Color
with Color.info:
print("This will be in the specified color")
print("You can print as much as you want in the with-statement")
print("This will be in the default color again")
Color combinations
Here it shows the used ANSI codes in its respective style and color. The following are the numbers that are used under the hood (the Color class uses the numbers 0-8 for everything)
First number (0-7): Style
Second number(30-37): Text color
Third number(40-47): Background color
Style 0
Style 1
Style 2
Style 3
Style 4
Style 5
Style 6
Style 7
Misc
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 color_console_py-0.1.1.tar.gz
.
File metadata
- Download URL: color_console_py-0.1.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9813a1dad88b56e1d4745bac12981d8477514f2018aca9d72b20af672e380742 |
|
MD5 | 9a8a55db1e0e3031e8618e7fc7825606 |
|
BLAKE2b-256 | 2ca9c3bcbb6f93f214f23320f75396940e73cf20f6198c25829dbe67a9dda234 |
File details
Details for the file color_console_py-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: color_console_py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f474d1e72761d73b56093948b7684bdbbad56784047f825330302b3ac0a24675 |
|
MD5 | fc428481b834dca1fafe4764c19042a1 |
|
BLAKE2b-256 | c0b953de54a02d67ceba252cd4102f328532be444784768bfd5464201f88f879 |