A lightweight Python package for adding customizable terminal colors.
Project description
ptcolors Repository
ptcolors
is a lightweight Python package designed to add vibrant, customizable colors to your terminal output with minimal effort. Whether you’re building command-line applications and scripts or simply want to enhance the readability of your terminal messages, ptcolors
provides an easy-to-use interface to bring your text to life.
With ptcolors
, you can apply a wide range of colors and styles to your terminal text, making it more engaging and visually appealing. It's perfect for developers who want to add a splash of color to their terminal without dealing with the complexities of ANSI escape codes.
Project Status
Here's the current status of our workflows:
Workflow | Status |
---|---|
Continuous Integration | |
Documentation | |
Guard Main Branch | |
Code Quality Checker |
Components
The ptcolors's codebase structure is as shown below:
.
├── LICENSE
├── README.md
├── MANIFEST.in
├── VERSION
├── build_docs
│ ├── Makefile
│ ├── __init__.py
│ ├── build
│ ├── make.bat
│ └── src
│ ├── __init__.py
│ ├── _static
│ ├── _templates
│ ├── conf.py
│ ├── index.rst
│ └── ptcolors.rst
├── requirements
│ ├── testing.txt
├── requirements.txt
├── setup.py
└── src
├── ptcolors
│ ├── __init__.py
│ └── ptcolors.py
└── tests
├── __init__.py
└── test_ptcolors.py
Example
Here's an example of how to use ptcolors
:
# import the PTColors class
from ptcolors.ptcolors import PTColors
# create a msg object
msg = PTColors()
# use the msg methods
msg.headermsg("This is a header message.")
msg.okmsg("This is a success message.")
msg.warnmsg("This is a warning message.")
msg.failmsg("This is a failure message.")
msg.infomsg("This is an info message.")
This should create a terminal output similar to the one below.
Here’s an example of using a context manager to handle resources, like managing messages during a function’s execution. Context managers in Python, typically implemented with the with statement, allow you to control resource allocation and release efficiently. Here we demonstrate using the PTColors context manager.
# import the PTColors class
from ptcolors.ptcolors import PTColors
from builtins import RuntimeError
# instanstiate a PTColors object called msg
msg = PTColors()
# define a callback function foo that takes an argument bar
def foo(bar: str) -> None:
"""A simple function that prints the argument passed to it."""
# Use the context manager messages in the script
with msg.messages(
"Running the foo function...", # Message displayed at the start
"foo function complete...", # Message displayed on successful completion
"foo function experienced a problem!", # Message displayed on failure
foo, # The callback or function to be executed (foo)
*["bar",], # Positional arguments for the function (bar)
**{"Exception": RuntimeError, }, # The Required keyword arguments
) as status:
if not status:
print("Hooray!")
else:
print("Oh no!")
This should create a terminal output similar to the one below.
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
Built Distribution
File details
Details for the file ptcolors-0.1.6.tar.gz
.
File metadata
- Download URL: ptcolors-0.1.6.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ecba9946877282b9d2f0b6f1ca57827cb9e184c73921009fb75bb64f882dcfa |
|
MD5 | 9e993e95ef932b1910c137fe0b388caf |
|
BLAKE2b-256 | d0b722f58c47df80cf07392c8468a3b2cf1509c0a0bdf4c6968667a5a9ee67c1 |
File details
Details for the file ptcolors-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: ptcolors-0.1.6-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b6e41a789b4eb8b4a685dde1e04dec8cb59e2797b3ab04596da0fa86c61b10d |
|
MD5 | 13f1bb28de759df5bfb21d39da30fa94 |
|
BLAKE2b-256 | a5e4ede8acc1a7eb3af2fd454e8c99611827f88609d9f90a963fdda6fab9b990 |