Skip to main content

A lightweight Python package for adding customizable terminal colors.

Project description

ptcolors Package

GitHub license GitHub release (latest by date) GitHub issues GitHub pull requests GitHub contributors GitHub last commit GitHub commit activity GitHub top language GitHub search hit counter GitHub stars GitHub watchers

ptcolors is a lightweight Python package designed to add vibrant color messages 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
Testing Suite Continuous-Integration
Deployment Suite Continuous-Deployment
Sphinx Documentation Sphinx-docs
Guard Main Branch Guard Main Branch
Code Quality Checker Lint Codebase

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.

Example 1 Output

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 and variable keyword arguments
def foo(bar: str, **kwargs) -> None:
    """A function that does nothing."""

# 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, },        # Optional keyword arguments and optional arguments
                                            # for the callback function
) as status:
    if status:
        print("Oh no!")
    else:
        print("Hooray!")

This should create a terminal output similar to the one below.

Example 2 Output

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

ptcolors-1.0.2.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ptcolors-1.0.2-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file ptcolors-1.0.2.tar.gz.

File metadata

  • Download URL: ptcolors-1.0.2.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for ptcolors-1.0.2.tar.gz
Algorithm Hash digest
SHA256 7424e7c33d2ebace66afdea15321a4fcde2dd92af9988cc08c248dad3ac1d7c8
MD5 abbbfad97949792bd8ad9ec79f1682e5
BLAKE2b-256 d6f199750960864f86212801c6da2a317f473e4765e5073e666d0540d8efc84b

See more details on using hashes here.

File details

Details for the file ptcolors-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: ptcolors-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for ptcolors-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fff6478fbc0eabca8f9af1d70b6dca43da31f539fb1ebde756aa847019883739
MD5 4b63ac0e727c386df93925a4174bb865
BLAKE2b-256 a4d4ec90d808adf56f86e95844540e818e2233a06b1c7744445a3aa3c75815cd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page