Skip to main content

A simple library for colored terminal output 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-1.0.1.tar.gz (6.8 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-1.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for terminal_colorize-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9875ad3ee2ca4e1eefa338bf49542f09cc993e70c2cebb7990c6a2437530caad
MD5 a2367416ce00664ea31be1e3a789effb
BLAKE2b-256 042317d759300e5bd2b600e6c039aff5ef008817381eada937db35fb637ee00f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for terminal_colorize-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 801e9c83651a7bae2424db7bcc23fb6ed548cbc33f0f6c789f1e020969fb88be
MD5 12b4eb1320b055bd196dbc5c363227e0
BLAKE2b-256 c8c9d059f6abe5dc3b137d1e7157b26d28609ae24a5f4722fa1abaf6a26d163a

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