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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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