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()andstylize() - 🎯 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 redprint_green(text)- Print in greenprint_yellow(text)- Print in yellowprint_blue(text)- Print in blueprint_magenta(text)- Print in magentaprint_cyan(text)- Print in cyanprint_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 ✓ checkmarkprint_error(text)- Red text with ✗ crossprint_warning(text)- Yellow text with ⚠ warning signprint_info(text)- Cyan text with ℹ info icon
Style Functions
print_bold(text)- Bold textprint_italic(text)- Italic textprint_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.BOLDStyles.ITALICStyles.UNDERLINEStyles.DIMStyles.BLINKStyles.REVERSEStyles.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[31mmakes text red\033[1mmakes text bold\033[0mresets 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9875ad3ee2ca4e1eefa338bf49542f09cc993e70c2cebb7990c6a2437530caad
|
|
| MD5 |
a2367416ce00664ea31be1e3a789effb
|
|
| BLAKE2b-256 |
042317d759300e5bd2b600e6c039aff5ef008817381eada937db35fb637ee00f
|
File details
Details for the file terminal_colorize-1.0.1-py3-none-any.whl.
File metadata
- Download URL: terminal_colorize-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
801e9c83651a7bae2424db7bcc23fb6ed548cbc33f0f6c789f1e020969fb88be
|
|
| MD5 |
12b4eb1320b055bd196dbc5c363227e0
|
|
| BLAKE2b-256 |
c8c9d059f6abe5dc3b137d1e7157b26d28609ae24a5f4722fa1abaf6a26d163a
|