Skip to main content

Enhanced print function with timestamping, styling, and color options.

Project description


pycprint Library Documentation

Introduction

pycprint is a Python library designed to enhance terminal output with customizable text styling, timestamping, colorization, and file redirection capabilities. This document provides an in-depth guide to understanding and using all functionalities offered by the pycprint library.

Installation

Install pycprint via pip, Python's package installer:

pip install pycprint

Usage

Import and use the cprint function from pycprint to enhance your terminal output:

from pycprint import pycprint

cprint = pycprint.pycprint

cprint("Hello, World!")

Features Overview

1. Text Styling

Enhance your messages with various text styles:

  • bold
  • underline
  • italic
  • inverse
  • strikethrough

Example:

cprint("Important message", style='bold')
cprint("Highlighted text", style='underline')

2. Timestamping

Prefix messages with a timestamp in the format [YYYY-MM-DD HH:MM:SS]:

cprint("Event occurred", timestamp=True)

3. Custom Prefix

Prefix messages with a custom string for clarity:

cprint("Error", prefix="ERROR")

4. Text and Background Color

Customize text and background colors using predefined color names:

  • Text colors: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE
  • Background colors: Same options as text colors

Example:

cprint("Success", color='GREEN')
cprint("Highlighted", bg='YELLOW')

5. File Output

Redirect output to a specified file:

cprint("Logged message", file='logfile.txt')

6. Cursor Control

Toggle cursor visibility during printing:

cprint("Loading...", cursor='false')

7. Advanced Features

  • Combining Features: Combine multiple features together for complex output requirements.

    cprint("Critical error occurred!", style='bold', timestamp=True, prefix="ERROR", color='RED')
    

Examples

Here are additional examples demonstrating various combinations of features:

Example 1: Styled and Timestamped Message

cprint("Critical error occurred!", style='bold', timestamp=True)

Output:

[2024-06-13 15:30:00] Critical error occurred!

Example 2: Colored Output with Custom Prefix

cprint("Operation successful", prefix="STATUS", color='GREEN', bg='BLACK')

Output (colored depending on your terminal):

STATUS: Operation successful

Example 3: Redirecting Output to a File

cprint("Debug information", file='debug.log')

Output: (written to debug.log file)

Example 4: Hiding Cursor During Loading

cprint("Loading...", cursor='false')

Output:

Loading... (cursor hidden)

Notes

  • Ensure colorama is installed (pip install colorama) for ANSI color code support.
  • The library gracefully handles errors, printing messages for invalid parameters while continuing with the print operation.

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

pycprint-1.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

pycprint-1.1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file pycprint-1.1.0.tar.gz.

File metadata

  • Download URL: pycprint-1.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for pycprint-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d2ee2e778ff2e205b7ff0ad77ea4df33fe3d6db061068df5a6c1891f0e8e34fb
MD5 c6c3029d5b1ce5339d38c8d82c38086f
BLAKE2b-256 cf5e4d37237b0e78bf6ae62db77251274463eea7c2f6162dd1ef7dfafd079597

See more details on using hashes here.

File details

Details for the file pycprint-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pycprint-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for pycprint-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75fb1d181355b33d070bcf3362c63098fcb3e9487323a5850e514055a49b2e7f
MD5 b1475d3a133cda779e3bca0447160757
BLAKE2b-256 1517323da63dc4d1108df0b259121b4d82412aa2261fa2d403f64c0f030e9459

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