Skip to main content

A comprehensive library for colored terminal output, progress bars, tables, and shapes using ANSI escape codes

Project description

ColorTerm 🎨

A simple Python library for printing colored and styled text to the terminal using ANSI escape codes. Perfect for making your CLI applications more readable and user-friendly!

Features

  • 🎨 8 basic colors + 4 bright colors
  • ✨ Text styling (bold, italic, underline, etc.)
  • 🚦 Semantic functions (print_success, print_error, print_warning, print_info)
  • 🔧 Manual colorization with colorize() and stylize()
  • 🎯 Simple, intuitive API

Installation

Install via pip:

pip install terminal-colorize

Or install from source:

git clone https://github.com/mmssajith/colorterm.git
cd colorterm
pip install -e .

Quick Start

from colorterminal import *

# Simple colored output
print_green("Operation successful!")
print_red("Error occurred!")

# Semantic messages with icons
print_success("File saved successfully!")
print_error("Failed to connect to server!")
print_warning("Disk space is running low!")
print_info("Processing 100 items...")

# Styled text
print_bold("Important message")
print_underline("Underlined text")

# Combined styles
print_bold_green("Bold green text")

API Reference

Basic Color Functions

  • print_red(text) - Print in red
  • print_green(text) - Print in green
  • print_yellow(text) - Print in yellow
  • print_blue(text) - Print in blue
  • print_magenta(text) - Print in magenta
  • print_cyan(text) - Print in cyan
  • print_white(text) - Print in white

Bright Color Functions

  • print_bright_red(text)
  • print_bright_green(text)
  • print_bright_yellow(text)
  • print_bright_blue(text)
  • And more...

Semantic Functions

  • print_success(text) - Green text with ✓ checkmark
  • print_error(text) - Red text with ✗ cross
  • print_warning(text) - Yellow text with ⚠ warning sign
  • print_info(text) - Cyan text with ℹ info icon

Style Functions

  • print_bold(text) - Bold text
  • print_italic(text) - Italic text
  • print_underline(text) - Underlined text

Combined Functions

  • print_bold_red(text)
  • print_bold_green(text)
  • print_bold_yellow(text)

Manual Colorization

For more control, use the colorize() and stylize() functions:

# Custom color
print(colorize("Custom text", Colors.MAGENTA))

# Multiple styles
print(stylize("Fancy text", Styles.BOLD, Styles.UNDERLINE, Colors.CYAN))

# Mix with regular text
print(f"Status: {colorize('ONLINE', Colors.GREEN)}")

Available Color Codes

Access via the Colors class:

  • Colors.RED, Colors.GREEN, Colors.YELLOW, Colors.BLUE, etc.
  • Colors.BRIGHT_RED, Colors.BRIGHT_GREEN, etc.
  • Colors.BG_RED, Colors.BG_GREEN, etc. (background colors)

Available Style Codes

Access via the Styles class:

  • Styles.BOLD
  • Styles.ITALIC
  • Styles.UNDERLINE
  • Styles.DIM
  • Styles.BLINK
  • Styles.REVERSE
  • Styles.STRIKETHROUGH

Examples

Check the examples/ directory for sample code, or run:

python examples/example.py

Practical Example

from colorterminal import *

print_info("Starting backup process...")

try:
    # Backup code here
    files_backed_up = 42
    print_success(f"Backup completed! {files_backed_up} files backed up.")
except Exception as e:
    print_error(f"Backup failed: {e}")

print_warning("Remember to verify your backups regularly!")

Status Dashboard Example

from colorterminal import *

print(f"Server Status: {colorize('ONLINE', Colors.GREEN)}")
print(f"Active Users: {colorize('127', Colors.CYAN)}")
print(f"Errors: {colorize('0', Colors.GREEN)}")
print(f"Warnings: {colorize('3', Colors.YELLOW)}")

How It Works

ColorTerm uses ANSI escape codes to color and style terminal text. For example:

  • \033[31m makes text red
  • \033[1m makes text bold
  • \033[0m resets formatting

The library abstracts these codes into easy-to-use functions, so you don't need to remember the codes!

Compatibility

Works on:

  • ✅ Linux
  • ✅ macOS
  • ✅ Windows (Windows 10+ with ANSI support enabled)

License

MIT License - see LICENSE file for details.

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

terminal_colorize-2.0.0.tar.gz (30.9 kB view details)

Uploaded Source

Built Distribution

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

terminal_colorize-2.0.0-py3-none-any.whl (44.2 kB view details)

Uploaded Python 3

File details

Details for the file terminal_colorize-2.0.0.tar.gz.

File metadata

  • Download URL: terminal_colorize-2.0.0.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for terminal_colorize-2.0.0.tar.gz
Algorithm Hash digest
SHA256 336c222ed5c72451847bc9227e40ae3c9be05b8a607d20fb6df21f887c9154c1
MD5 17ac42f9b583471f56453ba3bc3b94a4
BLAKE2b-256 2e9c00a4389318708fc9c470daf45f868be895754dfc632cd8b7fc37a09c572b

See more details on using hashes here.

File details

Details for the file terminal_colorize-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for terminal_colorize-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cb4bcbcb54912163581b1db312e4744087898317d00f0c4bf3897864df1a96d
MD5 d825d9310d35145b86c310763f168e29
BLAKE2b-256 fe2af162e323fcac606425b3908d1f9607947aab32ab5b21269861f7b7a1f869

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