Colorist for Python
Project description
🌈 Colorist for Python 🌈
Lightweight Python package that makes it easy and fast to print terminal messages in colors.
Prerequisites
- Python 3.9 or higher
- macOS
- It may work on Windows or Linux, but hasn't been tested
Installation
PyPI
pip3 install colorist
Homebrew
If you already have installed the Homebrew package manager for Mac and Linux, use this terminal command to tap Colorist for Python:
brew tap jakob-bagterp/colorist
And then install:
brew install colorist
Text Colors
Getting Started
Full Terminal Output
How to print a full line of colored text in the terminal:
from colorist import green, yellow, red
green("This is GREEN!")
yellow("This is YELLOW!")
red("This is RED!")
How it appears in the terminal:
Custom Terminal Output
How to customize terminal messages and change color inside a paragraph:
from colorist import Color
print(f"I want {Color.RED}red{Color.OFF} color inside this paragraph")
print(f"Both {Color.GREEN}green{Color.OFF} and {Color.YELLOW}yellow{Color.OFF} are nice colors")
How it appears in the terminal:
from colorist import BrightColor
print(f"I want {BrightColor.CYAN}cyan{BrightColor.OFF} color inside this paragraph")
How it appears in the terminal:
Remember to use Color.OFF
or BrightColor.OFF
every time you want to revert back to the default terminal text style. Otherwise the color may spill over and into other terminal messages.
Other String Formats
It's easier and more readable to use f-strings as in the examples above, but you can also use string format:
from colorist import Color
print("I want {0}red{1} color inside this paragraph".format(Color.RED, Color.OFF))
How it appears in the terminal:
Supported Text Colors
Color | Full Text Function | Custom | Example |
---|---|---|---|
green("text") | Color.GREEN | ||
yellow("text") | Color.YELLOW | ||
red("text") | Color.RED | ||
magenta("text") | Color.MAGENTA | ||
blue("text") | Color.BLUE | ||
cyan("text") | Color.CYAN | ||
white("text") | Color.WHITE | ||
black("text") | Color.BLACK | ||
- | - | Color.OFF | - |
bright_green("text") | BrightColor.GREEN | ||
bright_yellow("text") | BrightColor.YELLOW | ||
bright_red("text") | BrightColor.RED | ||
bright_magenta("text") | BrightColor.MAGENTA | ||
bright_blue("text") | BrightColor.BLUE | ||
bright_cyan("text") | BrightColor.CYAN | ||
bright_white("text") | BrightColor.WHITE | ||
bright_black("text") | BrightColor.BLACK | ||
- | - | BrightColor.OFF | - |
Background Colors
Getting Started
Full Terminal Output
How to print a full line of text with colored background in the terminal:
from colorist import bg_green, bg_yellow, bg_red
bg_green("This is GREEN background!")
bg_yellow("This is YELLOW background!")
bg_red("This is RED background!")
How it appears in the terminal:
Custom Terminal Output
How to customize terminal messages and change background color inside a paragraph:
from colorist import BgColor
print(f"I want {BgColor.RED}red{BgColor.OFF} background color inside this paragraph")
print(f"Both {BgColor.GREEN}green{BgColor.OFF} and {BgColor.YELLOW}yellow{BgColor.OFF} are nice background colors")
How it appears in the terminal:
from colorist import BgBrightColor
print(f"I want {BgBrightColor.CYAN}cyan{BgBrightColor.OFF} background color inside this paragraph")
How it appears in the terminal:
As with text colors, remember to use BgColor.OFF
or BgBrightColor.OFF
every time you want to revert back to the default terminal text style. Otherwise the color may spill over and into other terminal messages.
Supported Background Colors
Color | Full Text Function | Custom | Example |
---|---|---|---|
bg_green("text") | BgColor.GREEN | ||
bg_yellow("text") | BgColor.YELLOW | ||
bg_red("text") | BgColor.RED | ||
bg_magenta("text") | BgColor.MAGENTA | ||
bg_blue("text") | BgColor.BLUE | ||
bg_cyan("text") | BgColor.CYAN | ||
bg_white("text") | BgColor.WHITE | ||
bg_black("text") | BgColor.BLACK | ||
- | - | BgColor.OFF | - |
bg_bright_green("text") | BgBrightColor.GREEN | ||
bg_bright_yellow("text") | BgBrightColor.YELLOW | ||
bg_bright_red("text") | BgBrightColor.RED | ||
bg_bright_magenta("text") | BgBrightColor.MAGENTA | ||
bg_bright_blue("text") | BgBrightColor.BLUE | ||
bg_bright_cyan("text") | BgBrightColor.CYAN | ||
bg_bright_white("text") | BgBrightColor.WHITE | ||
bg_bright_black("text") | BgBrightColor.BLACK | ||
- | - | BgBrightColor.OFF | - |
Effects
Getting Started
In addition to colors, Colorist for Python can also add effects to text messages in the terminal.
Full Terminal Output
How to print a full line of text effect in the terminal:
from colorist import effect_blink
effect_blink("This is BLINKING!")
How it appears in the terminal:
And this can also be combined with an optional color:
from colorist import Color, effect_blink
effect_blink("This is BLINKING!", Color.CYAN)
How it appears in the terminal:
Custom Terminal Output
How to customize terminal messages and change effect inside a paragraph:
from colorist import Effect
print(f"I want {Effect.UNDERLINE}underlined text{Effect.UNDERLINE_OFF} inside this paragraph")
print(f"I want {Effect.BOLD}emphasized text{Effect.BOLD_OFF} inside this paragraph")
How it appears in the terminal:
Effects can also be mixed with colors:
from colorist import Color, Effect
print(f"I want both {Color.RED}colored and {Effect.BLINK}blinking{Effect.BLINK_OFF} text{Color.OFF} inside this paragraph")
Similar to Color.OFF
, remember to turn off an effect with the relevant reset option (e.g Effect.BOLD_OFF
, Effect.DIM_OFF
, etc. or even just Effect.OFF
) every time you want to revert back to the default terminal text style. Otherwise the effect may spill over and into other terminal messages.
Supported Effects
Effect | Full Text Function | Custom | Reset | Example |
---|---|---|---|---|
Bold | effect_bold("text") | Effect.BOLD | Effect.BOLD_OFF | |
Dim | effect_dim("text") | Effect.DIM | Effect.DIM_OFF | |
Underline | effect_underline("text") | Effect.UNDERLINE | Effect.UNDERLINE_OFF | |
Blink | effect_blink("text") | Effect.BLINK | Effect.BLINK_OFF | |
Reverse | effect_reverse("text") | Effect.REVERSE | Effect.REVERSE_OFF | |
Hide | effect_hide("text") | Effect.HIDE | Effect.HIDE_OFF | |
- | - | - | Effect.OFF | - |
Donate
This module is free to use. And if you like it, feel free to buy me a coffee.
Contribute
If you have suggestions or changes to the module, feel free to add to the code and create a pull request.
Report Bugs
Report bugs and issues here.
MIT License
Copyright (c) 2022 – present Jakob Bagterp
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 colorist-1.1.0.tar.gz
.
File metadata
- Download URL: colorist-1.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c81e0525405d5aba8df9e47d7e78e6183fc29b99040474dcd8d3946162df94f |
|
MD5 | e4fe3cf5b9efa13ff43c3c7462742c2b |
|
BLAKE2b-256 | d47ca7f9c745f263ba908d4eafd2ce84ef86387c441a379959de0fab8013c138 |
File details
Details for the file colorist-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: colorist-1.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97d7c4aa7db23ed2099018e28bf0807f4cb838bfbb0263063f5ee1af43c2461f |
|
MD5 | 5bf9df050e16627e7eeeeba419015e7d |
|
BLAKE2b-256 | 6817e41ee52664a49192162f46d08c790a4e6412e029dbf7e4cf566080de0ebe |