# 🎨 make\_colors
A simple, powerful, and cross-platform Python library for adding colors, styles, and rich markup support to your terminal output. Optimized for **Windows 10+**, Linux, and macOS.
[](https://python.org)
[](https://github.com)
[](LICENSE)
## 📋 Table of Contents
* [✨ Features](#-features)
* [📦 Installation](#-installation)
* [🚀 Quick Start](#-quick-start)
* [🎨 Color Reference](#-color-reference)
* [💡 Usage Examples](#-usage-examples)
* [🌍 Environment Variables](#-environment-variables)
* [📚 API Reference](#-api-reference)
* [🖋 Rich Markup Support](#-rich-markup-support)
* [🖥️ Platform Support](#-platform-support)
* [🛠️ Development & Testing](#-development--testing)
* [🎯 Best Practices](#-best-practices)
* [⚠️ Error Handling](#️-error-handling)
* [📊 Performance](#-performance)
* [📑 Quick Reference](#-quick-reference)
* [🤝 Contributing](#-contributing)
* [📄 License](#-license)
* [👨💻 Author](#-author)
[](https://github.com/cumulus13/make_colors/raw/refs/heads/master/example_usage.gif)
---
## ✨ Features
* 🖥️ **Cross-platform support** – Works on Windows, Linux, and macOS
* 🎯 **Windows 10+ optimized** – Uses native ANSI processing on Windows Console
* 🌈 **Rich color palette** – 16 standard colors with light variants
* 📝 **Simple syntax** – Full names, abbreviations, and combined formats
* 🔧 **Flexible formatting** – Foreground, background, and text attributes
* 🖋 **Rich markup** – Parse and render `[red]Error[/]` or `[bold white on red]CRITICAL[/]`
* 🚀 **Lightweight** – Zero external dependencies
* 🎛️ **Environment control** – Enable/disable colors globally with env vars
* 🛡 **Error handling** – Graceful fallbacks when unsupported colors are used
---
## 📦 Installation
```bash
pip install make_colors
```
---
## 🚀 Quick Start
```python
from make_colors import make_colors
# Simple colored text
print(make_colors("Hello World!", "red"))
# Text with background
print(make_colors("Important Message", "white", "red"))
# Using shortcuts
print(make_colors("Quick and easy", "r", "bl")) # red text, blue background
# Using underscore notation
print(make_colors("One-liner style", "green_yellow")) # green text on yellow background
# Rich markup
print(make_colors("[bold white on red] CRITICAL [/]") )
# import all
from make_colors import *
print(bl("Im Blue"))
color = Colors('red', 'white')
print(color("White on Red"))
color = Color('white', 'red')
print(color("TEST"))
```
---
## 🎨 Color Reference
### Available Colors
| Color Name | Shortcuts | Light Variant | Light Shortcut |
| ---------- | ------------- | ------------- | -------------- |
| black | b, bk | lightblack | lb |
| red | r, rd, re | lightred | lr |
| green | g, gr, ge | lightgreen | lg |
| yellow | y, ye, yl | lightyellow | ly |
| blue | bl | lightblue | lb |
| magenta | m, mg, ma | lightmagenta | lm |
| cyan | c, cy, cn | lightcyan | lc |
| white | w, wh, wi, wt | lightwhite | lw |
### Color Preview
```python
# Standard colors
print(make_colors("■ Black text", "black"))
print(make_colors("■ Red text", "red"))
print(make_colors("■ Green text", "green"))
print(make_colors("■ Yellow text", "yellow"))
print(make_colors("■ Blue text", "blue"))
print(make_colors("■ Magenta text", "magenta"))
print(make_colors("■ Cyan text", "cyan"))
print(make_colors("■ White text", "white"))
# Light variants
print(make_colors("■ Light Red", "lightred"))
print(make_colors("■ Light Green", "lightgreen"))
print(make_colors("■ Light Blue", "lightblue"))
print(make_colors("■ Light Yellow", "lightyellow"))
```
---
## 💡 Usage Examples
### Basic Usage
```python
print(make_colors("Full color names", "red", "white"))
print(make_colors("Using shortcuts", "r", "w"))
print(make_colors("Mixed notation", "red", "w"))
```
### Separator Notation
```python
# Using underscore separator
print(make_colors("Error occurred!", "red_white"))
print(make_colors("Success!", "green_black"))
print(make_colors("Warning!", "yellow_red"))
# Using dash separator
print(make_colors("Info message", "blue-white"))
print(make_colors("Debug info", "cyan-black"))
# Using comma separator
print(make_colors("Critical message", "white,blue"))
print(make_colors("Alert info", "w,r"))
```
### Advanced Examples
```python
# System status display
def show_status(service, status):
if status == "running":
return make_colors(f"[✓] {service}", "lightgreen", "black")
elif status == "stopped":
return make_colors(f"[✗] {service}", "lightred", "black")
else:
return make_colors(f"[?] {service}", "lightyellow", "black")
print(show_status("Web Server", "running"))
print(show_status("Database", "stopped"))
print(show_status("Cache", "unknown"))
# Log level formatting
def log_message(level, message):
colors = {
"ERROR": ("lightwhite", "red"),
"WARNING": ("black", "yellow"),
"INFO": ("lightblue", "black"),
"DEBUG": ("lightgrey", "black")
}
fg, bg = colors.get(level, ("white", "black"))
return f"{make_colors(f' {level} ', fg, bg)} {message}"
print(log_message("ERROR", "Connection failed"))
print(log_message("WARNING", "Deprecated method used"))
print(log_message("INFO", "Server started successfully"))
print(log_message("DEBUG", "Variable value: 42"))
```
### Attributes
```python
print(make_colors("Bold text", "red", attrs=["bold"]))
print(make_colors("Underlined", "blue", attrs=["underline"]))
print(make_colors("Italic + Bold", "green", attrs=["italic", "bold"]))
```
### Progress Bar Indicators
```python
import time
for i in range(0, 101, 20):
bar = "█" * (i // 5) + "░" * (20 - i // 5)
print(f"\r{make_colors(f'[{bar}] {i}%', 'yellow')}", end="")
time.sleep(0.2)
print()
def progress_bar(current, total, width=50):
percentage = current / total
filled = int(width * percentage)
bar = "█" * filled + "░" * (width - filled)
if percentage < 0.5:
color = "red"
elif percentage < 0.8:
color = "yellow"
else:
color = "green"
return make_colors(f"[{bar}] {current}/{total} ({percentage:.1%})", color)
# Simulate progress
for i in range(0, 101, 10):
print(f"\r{progress_bar(i, 100)}", end="", flush=True)
time.sleep(0.1)
print() # New line after completion
```
### Menu Systems
```python
def create_menu():
options = [
("1", "Start Application", "green"),
("2", "Settings", "yellow"),
("3", "Help", "blue"),
("4", "Exit", "red")
]
print(make_colors(" 🎯 Main Menu ", "white", "blue"))
print()
for key, option, color in options:
print(f" {make_colors(key, 'white', color)} {option}")
print()
return input("Select option: ")
# Usage
choice = create_menu()
```
---
## 🌍 Environment Variables
| Variable | Values | Description |
| ------------------- | ------------------- | ---------------------------------- |
| `MAKE_COLORS` | `0` or `1` | Disable/enable colors globally |
| `MAKE_COLORS_FORCE` | `0`, `1`, `True` | Force colors even when unsupported |
| `MAKE_COLORS_DEBUG` | `1`, `true`, `True` | Enable debug parsing logs |
Example:
```python
import os
# Disable colors
os.environ['MAKE_COLORS'] = '0'
print(make_colors("No colors", "red")) # Output: "No colors" (no coloring)
# Force colors (useful for CI/CD or redirected output)
os.environ['MAKE_COLORS_FORCE'] = '1'
print(make_colors("Forced colors", "green")) # Always colored
```
---
## 📚 API Reference
### `make_colors(string, foreground='white', background=None, attrs=[], force=False)`
Main function to colorize strings with ANSI or Rich markup.
* `string` *(str)* – Input text, supports Rich markup like `[red]Error[/]`
* `foreground` *(str)* – Foreground color
* `background` *(str|None)* – Background color
* `attrs` *(list)* – List of attributes: `bold`, `underline`, `italic`, etc.
* `force` *(bool)* – Force enable colors
**Returns:**
- `str` (Colorized string with ANSI string escape codes)
---
### `make_color(...)`
Alias for `make_colors`.
### `print(string, ...)`
Convenience print wrapper that applies `make_colors` before printing.
### `parse_rich_markup(text)`
Parses strings like `[bold red on black]Hello[/]` into `(content, fg, bg, style)` tuples. Supports multiple tags.
### `getSort(data, foreground, background)`
Parses combined formats like `red-yellow`, `g_b`, expanding into `(fg, bg)`.
### `color_map(code)`
Maps abbreviations like `r`, `bl`, `lg` to full names.
**Examples:**
```python
# Basic usage
make_colors("Hello", "red")
# With background
make_colors("Hello", "white", "red")
# Using shortcuts
make_colors("Hello", "w", "r")
# Separator notation
make_colors("Hello", "white_red")
# Force colors
make_colors("Hello", "red", force=True)
```
### `MakeColors` class
* `colored(string, fg, bg, attrs)` → low-level ANSI output
* `rich_colored(string, color, bg, style)` → Rich style support
* `supports_color()` → Detect terminal support, return: `bool`: True if colors are supported, False otherwise
```python
from make_colors import MakeColors
if MakeColors.supports_color():
print("Colors are supported!")
else:
print("Colors not supported on this terminal")
```
### Exceptions
* `MakeColorsError` – Raised when invalid colors are used
* `MakeColorsWarning` – Non-critical fallback warnings
---
## 🖋 Rich Markup Support
The library supports **Rich-style markup** similar to the `rich` package:
```python
print(make_colors("[red]Error[/] [bold white on blue]CRITICAL[/] [green]OK[/]"))
```
Supported styles:
* **bold**, **italic**, **underline**, **dim**, **blink**, **reverse**, **strikethrough**
---
## 🖥️ Platform Support
### Windows
* **Windows 10+** ✅ (full ANSI support)
* **Older Windows** ⚠️ requires ANSICON
* **Windows Terminal**: 👍 Excellent support with all features
### Linux/Unix
* **Most terminals**: ✅ Full support (xterm, gnome-terminal, konsole, etc.), almost all terminals supported
* **Tmux/Screen**: ✅ Supported
* **SSH sessions**: ✅ Supported when terminal supports colors
### macOS
- **Terminal.app**: ✅ Full support
- **iTerm2**: ✅ Excellent support
- **Other terminals**: ✅ Generally well supported
---
## 🛠️ Development & Testing
### Testing Colors
```python
def test_all_colors():
"""Test all available colors"""
colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
light_colors = [f'light{color}' for color in colors if color != 'black'] + ['lightgrey']
print("=== Standard Colors ===")
for color in colors:
print(make_colors(f" {color.ljust(10)}", color, "black"))
print("\n=== Light Colors ===")
for color in light_colors:
print(make_colors(f" {color.ljust(15)}", color, "black"))
# Run the test
test_all_colors()
```
### Check Support
```python
from make_colors import MakeColors
print("Supports colors:", MakeColors.supports_color())
```
```python
def test_all_colors():
"""Test all available colors"""
colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
light_colors = [f'light{color}' for color in colors if color != 'black'] + ['lightgrey']
print("=== Standard Colors ===")
for color in colors:
print(make_colors(f" {color.ljust(10)}", color, "black"))
print("\n=== Light Colors ===")
for color in light_colors:
print(make_colors(f" {color.ljust(15)}", color, "black"))
# Run the test
test_all_colors()
---
## 🎯 Best Practices
1. **Always check color support** `MakeColors.supports_color()` before production use
2. **Provide fallbacks** for environments without color support (e.g. plain text when disabled)
3. **Use env vars for CI/CD or logging**
4. **Choose contrasting colors** for better readability
5. **Test on multiple OSes/terminals/platforms** to ensure compatibility
```python
from make_colors import make_colors, MakeColors
def safe_print(text, fg="white", bg=None):
"""Safely print colored text with fallback"""
if MakeColors.supports_color():
print(make_colors(text, fg, bg))
else:
print(f"[{fg.upper()}] {text}")
# Usage
safe_print("This works everywhere!", "green")
```
## 🧙 Magick
```python
from make_colors import *
print(red("Error!"))
print(bl("Im Blue"))
print(green_on_black("Success"))
# Abbreviation
print(w_bl("White on Blue")) # white on blue
print(r_w("Red on White")) # red on white
print(g_b("Green on Black")) # green on black
print(lb_b("Light Blue on Black"))
color = Colors('red', 'white')
print(color("White on Red"))
color = Color('white', 'red')
print(color("TEST"))
# Try and see what happened 👏 😄
```
---
## ⚠️ Error Handling
* Invalid color → falls back to white on black
* Unknown attribute → ignored silently
* Raise `MakeColorsError` for invalid color names (if strict)
* Raise `MakeColorsWarning` for warnings
```python
try:
print(make_colors("Oops", "notacolor"))
except Exception as e:
print("Handled:", e)
```
---
## 📊 Performance
* Traditional call: \~0.00001s per render
* Rich markup parsing: slightly slower (\~+10–15%)
* Suitable for **high-frequency logging**
---
## 📑 Quick Reference
* ✅ Single color: `[red]text[/]`
* ✅ With background: `[white on red]text[/]`
* ✅ With style: `[bold green]text[/]`
* ✅ Combined: `[bold white on red]ALERT[/]`
* ✅ Multiple tags: `[cyan]Info[/] [red]Error[/]`
---
## 🤝 Contributing
PRs welcome! Open issues for feature requests or bugs.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
---
## 📄 License
Licensed under the **MIT License**. See [LICENSE](LICENSE).
---
## 👨💻 Author
**Hadi Cahyadi**
📧 [cumulus13@gmail.com](mailto:cumulus13@gmail.com)
[](https://www.buymeacoffee.com/cumulus13)
[](https://ko-fi.com/cumulus13)
[Support me on Patreon](https://www.patreon.com/cumulus13)
---
✨ Made with ❤️ by Hadi Cahyadi for colorful terminal experiences!
Raw data
{
"_id": null,
"home_page": "https://github.com/cumulus13/make_colors",
"name": "make-colors",
"maintainer": "cumulus13",
"docs_url": null,
"requires_python": ">=2.7",
"maintainer_email": "cumulus13@gmail.com",
"keywords": "color, terminal, console, ansi, text, colorize, cli, markup, rich_markup",
"author": "Hadi Cahyadi",
"author_email": "cumulus13@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5e/c9/8f522cb3e3e2222039140a0f3d14b1d311fdd995c9478fd83a945256645a/make_colors-3.48.3.tar.gz",
"platform": null,
"description": "# \ud83c\udfa8 make\\_colors\r\n\r\nA simple, powerful, and cross-platform Python library for adding colors, styles, and rich markup support to your terminal output. Optimized for **Windows 10+**, Linux, and macOS.\r\n\r\n[](https://python.org)\r\n[](https://github.com)\r\n[](LICENSE)\r\n\r\n## \ud83d\udccb Table of Contents\r\n\r\n* [\u2728 Features](#-features)\r\n* [\ud83d\udce6 Installation](#-installation)\r\n* [\ud83d\ude80 Quick Start](#-quick-start)\r\n* [\ud83c\udfa8 Color Reference](#-color-reference)\r\n* [\ud83d\udca1 Usage Examples](#-usage-examples)\r\n* [\ud83c\udf0d Environment Variables](#-environment-variables)\r\n* [\ud83d\udcda API Reference](#-api-reference)\r\n* [\ud83d\udd8b Rich Markup Support](#-rich-markup-support)\r\n* [\ud83d\udda5\ufe0f Platform Support](#-platform-support)\r\n* [\ud83d\udee0\ufe0f Development & Testing](#-development--testing)\r\n* [\ud83c\udfaf Best Practices](#-best-practices)\r\n* [\u26a0\ufe0f Error Handling](#\ufe0f-error-handling)\r\n* [\ud83d\udcca Performance](#-performance)\r\n* [\ud83d\udcd1 Quick Reference](#-quick-reference)\r\n* [\ud83e\udd1d Contributing](#-contributing)\r\n* [\ud83d\udcc4 License](#-license)\r\n* [\ud83d\udc68\u200d\ud83d\udcbb Author](#-author)\r\n\r\n[](https://github.com/cumulus13/make_colors/raw/refs/heads/master/example_usage.gif)\r\n\r\n---\r\n\r\n## \u2728 Features\r\n\r\n* \ud83d\udda5\ufe0f **Cross-platform support** \u2013 Works on Windows, Linux, and macOS\r\n* \ud83c\udfaf **Windows 10+ optimized** \u2013 Uses native ANSI processing on Windows Console\r\n* \ud83c\udf08 **Rich color palette** \u2013 16 standard colors with light variants\r\n* \ud83d\udcdd **Simple syntax** \u2013 Full names, abbreviations, and combined formats\r\n* \ud83d\udd27 **Flexible formatting** \u2013 Foreground, background, and text attributes\r\n* \ud83d\udd8b **Rich markup** \u2013 Parse and render `[red]Error[/]` or `[bold white on red]CRITICAL[/]`\r\n* \ud83d\ude80 **Lightweight** \u2013 Zero external dependencies\r\n* \ud83c\udf9b\ufe0f **Environment control** \u2013 Enable/disable colors globally with env vars\r\n* \ud83d\udee1 **Error handling** \u2013 Graceful fallbacks when unsupported colors are used\r\n\r\n---\r\n\r\n## \ud83d\udce6 Installation\r\n\r\n```bash\r\npip install make_colors\r\n```\r\n\r\n---\r\n\r\n## \ud83d\ude80 Quick Start\r\n\r\n```python\r\nfrom make_colors import make_colors\r\n\r\n# Simple colored text\r\nprint(make_colors(\"Hello World!\", \"red\"))\r\n\r\n# Text with background\r\nprint(make_colors(\"Important Message\", \"white\", \"red\"))\r\n\r\n# Using shortcuts\r\nprint(make_colors(\"Quick and easy\", \"r\", \"bl\")) # red text, blue background\r\n\r\n# Using underscore notation\r\nprint(make_colors(\"One-liner style\", \"green_yellow\")) # green text on yellow background\r\n\r\n# Rich markup\r\nprint(make_colors(\"[bold white on red] CRITICAL [/]\") )\r\n\r\n# import all \r\nfrom make_colors import *\r\n\r\nprint(bl(\"Im Blue\"))\r\ncolor = Colors('red', 'white')\r\nprint(color(\"White on Red\"))\r\ncolor = Color('white', 'red')\r\nprint(color(\"TEST\"))\r\n\r\n```\r\n\r\n---\r\n\r\n## \ud83c\udfa8 Color Reference\r\n\r\n### Available Colors\r\n\r\n| Color Name | Shortcuts | Light Variant | Light Shortcut |\r\n| ---------- | ------------- | ------------- | -------------- |\r\n| black | b, bk | lightblack | lb |\r\n| red | r, rd, re | lightred | lr |\r\n| green | g, gr, ge | lightgreen | lg |\r\n| yellow | y, ye, yl | lightyellow | ly |\r\n| blue | bl | lightblue | lb |\r\n| magenta | m, mg, ma | lightmagenta | lm |\r\n| cyan | c, cy, cn | lightcyan | lc |\r\n| white | w, wh, wi, wt | lightwhite | lw |\r\n\r\n### Color Preview\r\n\r\n```python\r\n# Standard colors\r\nprint(make_colors(\"\u25a0 Black text\", \"black\"))\r\nprint(make_colors(\"\u25a0 Red text\", \"red\"))\r\nprint(make_colors(\"\u25a0 Green text\", \"green\"))\r\nprint(make_colors(\"\u25a0 Yellow text\", \"yellow\"))\r\nprint(make_colors(\"\u25a0 Blue text\", \"blue\"))\r\nprint(make_colors(\"\u25a0 Magenta text\", \"magenta\"))\r\nprint(make_colors(\"\u25a0 Cyan text\", \"cyan\"))\r\nprint(make_colors(\"\u25a0 White text\", \"white\"))\r\n\r\n# Light variants\r\nprint(make_colors(\"\u25a0 Light Red\", \"lightred\"))\r\nprint(make_colors(\"\u25a0 Light Green\", \"lightgreen\"))\r\nprint(make_colors(\"\u25a0 Light Blue\", \"lightblue\"))\r\nprint(make_colors(\"\u25a0 Light Yellow\", \"lightyellow\"))\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udca1 Usage Examples\r\n\r\n### Basic Usage\r\n\r\n```python\r\nprint(make_colors(\"Full color names\", \"red\", \"white\"))\r\nprint(make_colors(\"Using shortcuts\", \"r\", \"w\"))\r\nprint(make_colors(\"Mixed notation\", \"red\", \"w\"))\r\n```\r\n\r\n### Separator Notation\r\n\r\n```python\r\n# Using underscore separator\r\nprint(make_colors(\"Error occurred!\", \"red_white\"))\r\nprint(make_colors(\"Success!\", \"green_black\"))\r\nprint(make_colors(\"Warning!\", \"yellow_red\"))\r\n\r\n# Using dash separator\r\nprint(make_colors(\"Info message\", \"blue-white\"))\r\nprint(make_colors(\"Debug info\", \"cyan-black\"))\r\n\r\n# Using comma separator\r\nprint(make_colors(\"Critical message\", \"white,blue\"))\r\nprint(make_colors(\"Alert info\", \"w,r\"))\r\n\r\n```\r\n\r\n### Advanced Examples\r\n\r\n```python\r\n# System status display\r\ndef show_status(service, status):\r\n if status == \"running\":\r\n return make_colors(f\"[\u2713] {service}\", \"lightgreen\", \"black\")\r\n elif status == \"stopped\":\r\n return make_colors(f\"[\u2717] {service}\", \"lightred\", \"black\")\r\n else:\r\n return make_colors(f\"[?] {service}\", \"lightyellow\", \"black\")\r\n\r\nprint(show_status(\"Web Server\", \"running\"))\r\nprint(show_status(\"Database\", \"stopped\"))\r\nprint(show_status(\"Cache\", \"unknown\"))\r\n\r\n# Log level formatting\r\ndef log_message(level, message):\r\n colors = {\r\n \"ERROR\": (\"lightwhite\", \"red\"),\r\n \"WARNING\": (\"black\", \"yellow\"),\r\n \"INFO\": (\"lightblue\", \"black\"),\r\n \"DEBUG\": (\"lightgrey\", \"black\")\r\n }\r\n \r\n fg, bg = colors.get(level, (\"white\", \"black\"))\r\n return f\"{make_colors(f' {level} ', fg, bg)} {message}\"\r\n\r\nprint(log_message(\"ERROR\", \"Connection failed\"))\r\nprint(log_message(\"WARNING\", \"Deprecated method used\"))\r\nprint(log_message(\"INFO\", \"Server started successfully\"))\r\nprint(log_message(\"DEBUG\", \"Variable value: 42\"))\r\n```\r\n\r\n### Attributes\r\n\r\n```python\r\nprint(make_colors(\"Bold text\", \"red\", attrs=[\"bold\"]))\r\nprint(make_colors(\"Underlined\", \"blue\", attrs=[\"underline\"]))\r\nprint(make_colors(\"Italic + Bold\", \"green\", attrs=[\"italic\", \"bold\"]))\r\n```\r\n\r\n### Progress Bar Indicators\r\n\r\n```python\r\nimport time\r\nfor i in range(0, 101, 20):\r\n bar = \"\u2588\" * (i // 5) + \"\u2591\" * (20 - i // 5)\r\n print(f\"\\r{make_colors(f'[{bar}] {i}%', 'yellow')}\", end=\"\")\r\n time.sleep(0.2)\r\nprint()\r\n\r\ndef progress_bar(current, total, width=50):\r\n percentage = current / total\r\n filled = int(width * percentage)\r\n bar = \"\u2588\" * filled + \"\u2591\" * (width - filled)\r\n \r\n if percentage < 0.5:\r\n color = \"red\"\r\n elif percentage < 0.8:\r\n color = \"yellow\"\r\n else:\r\n color = \"green\"\r\n \r\n return make_colors(f\"[{bar}] {current}/{total} ({percentage:.1%})\", color)\r\n\r\n# Simulate progress\r\nfor i in range(0, 101, 10):\r\n print(f\"\\r{progress_bar(i, 100)}\", end=\"\", flush=True)\r\n time.sleep(0.1)\r\nprint() # New line after completion\r\n```\r\n\r\n### Menu Systems\r\n\r\n```python\r\ndef create_menu():\r\n options = [\r\n (\"1\", \"Start Application\", \"green\"),\r\n (\"2\", \"Settings\", \"yellow\"),\r\n (\"3\", \"Help\", \"blue\"),\r\n (\"4\", \"Exit\", \"red\")\r\n ]\r\n \r\n print(make_colors(\" \ud83c\udfaf Main Menu \", \"white\", \"blue\"))\r\n print()\r\n \r\n for key, option, color in options:\r\n print(f\" {make_colors(key, 'white', color)} {option}\")\r\n \r\n print()\r\n return input(\"Select option: \")\r\n\r\n# Usage\r\nchoice = create_menu()\r\n```\r\n\r\n---\r\n\r\n## \ud83c\udf0d Environment Variables\r\n\r\n| Variable | Values | Description |\r\n| ------------------- | ------------------- | ---------------------------------- |\r\n| `MAKE_COLORS` | `0` or `1` | Disable/enable colors globally |\r\n| `MAKE_COLORS_FORCE` | `0`, `1`, `True` | Force colors even when unsupported |\r\n| `MAKE_COLORS_DEBUG` | `1`, `true`, `True` | Enable debug parsing logs |\r\n\r\nExample:\r\n\r\n```python\r\nimport os\r\n\r\n# Disable colors\r\nos.environ['MAKE_COLORS'] = '0'\r\nprint(make_colors(\"No colors\", \"red\")) # Output: \"No colors\" (no coloring)\r\n\r\n# Force colors (useful for CI/CD or redirected output)\r\nos.environ['MAKE_COLORS_FORCE'] = '1'\r\nprint(make_colors(\"Forced colors\", \"green\")) # Always colored\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udcda API Reference\r\n\r\n### `make_colors(string, foreground='white', background=None, attrs=[], force=False)`\r\n\r\nMain function to colorize strings with ANSI or Rich markup.\r\n\r\n* `string` *(str)* \u2013 Input text, supports Rich markup like `[red]Error[/]`\r\n* `foreground` *(str)* \u2013 Foreground color\r\n* `background` *(str|None)* \u2013 Background color\r\n* `attrs` *(list)* \u2013 List of attributes: `bold`, `underline`, `italic`, etc.\r\n* `force` *(bool)* \u2013 Force enable colors\r\n\r\n**Returns:**\r\n- `str` (Colorized string with ANSI string escape codes)\r\n\r\n---\r\n\r\n### `make_color(...)`\r\n\r\nAlias for `make_colors`.\r\n\r\n### `print(string, ...)`\r\n\r\nConvenience print wrapper that applies `make_colors` before printing.\r\n\r\n### `parse_rich_markup(text)`\r\n\r\nParses strings like `[bold red on black]Hello[/]` into `(content, fg, bg, style)` tuples. Supports multiple tags.\r\n\r\n### `getSort(data, foreground, background)`\r\n\r\nParses combined formats like `red-yellow`, `g_b`, expanding into `(fg, bg)`.\r\n\r\n### `color_map(code)`\r\n\r\nMaps abbreviations like `r`, `bl`, `lg` to full names.\r\n\r\n**Examples:**\r\n```python\r\n# Basic usage\r\nmake_colors(\"Hello\", \"red\")\r\n\r\n# With background\r\nmake_colors(\"Hello\", \"white\", \"red\")\r\n\r\n# Using shortcuts\r\nmake_colors(\"Hello\", \"w\", \"r\")\r\n\r\n# Separator notation\r\nmake_colors(\"Hello\", \"white_red\")\r\n\r\n# Force colors\r\nmake_colors(\"Hello\", \"red\", force=True)\r\n```\r\n\r\n### `MakeColors` class\r\n\r\n* `colored(string, fg, bg, attrs)` \u2192 low-level ANSI output\r\n* `rich_colored(string, color, bg, style)` \u2192 Rich style support\r\n* `supports_color()` \u2192 Detect terminal support, return: `bool`: True if colors are supported, False otherwise\r\n\r\n```python\r\nfrom make_colors import MakeColors\r\n\r\nif MakeColors.supports_color():\r\n print(\"Colors are supported!\")\r\nelse:\r\n print(\"Colors not supported on this terminal\")\r\n```\r\n\r\n### Exceptions\r\n\r\n* `MakeColorsError` \u2013 Raised when invalid colors are used\r\n* `MakeColorsWarning` \u2013 Non-critical fallback warnings\r\n\r\n---\r\n\r\n## \ud83d\udd8b Rich Markup Support\r\n\r\nThe library supports **Rich-style markup** similar to the `rich` package:\r\n\r\n```python\r\nprint(make_colors(\"[red]Error[/] [bold white on blue]CRITICAL[/] [green]OK[/]\"))\r\n```\r\n\r\nSupported styles:\r\n\r\n* **bold**, **italic**, **underline**, **dim**, **blink**, **reverse**, **strikethrough**\r\n\r\n---\r\n\r\n## \ud83d\udda5\ufe0f Platform Support\r\n\r\n\r\n### Windows\r\n* **Windows 10+** \u2705 (full ANSI support)\r\n* **Older Windows** \u26a0\ufe0f requires ANSICON\r\n* **Windows Terminal**: \ud83d\udc4d Excellent support with all features\r\n\r\n### Linux/Unix\r\n* **Most terminals**: \u2705 Full support (xterm, gnome-terminal, konsole, etc.), almost all terminals supported\r\n* **Tmux/Screen**: \u2705 Supported\r\n* **SSH sessions**: \u2705 Supported when terminal supports colors\r\n\r\n### macOS\r\n- **Terminal.app**: \u2705 Full support\r\n- **iTerm2**: \u2705 Excellent support\r\n- **Other terminals**: \u2705 Generally well supported\r\n---\r\n\r\n## \ud83d\udee0\ufe0f Development & Testing\r\n\r\n### Testing Colors\r\n\r\n```python\r\ndef test_all_colors():\r\n \"\"\"Test all available colors\"\"\"\r\n colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']\r\n light_colors = [f'light{color}' for color in colors if color != 'black'] + ['lightgrey']\r\n \r\n print(\"=== Standard Colors ===\")\r\n for color in colors:\r\n print(make_colors(f\" {color.ljust(10)}\", color, \"black\"))\r\n \r\n print(\"\\n=== Light Colors ===\")\r\n for color in light_colors:\r\n print(make_colors(f\" {color.ljust(15)}\", color, \"black\"))\r\n\r\n# Run the test\r\ntest_all_colors()\r\n```\r\n\r\n### Check Support\r\n\r\n```python\r\nfrom make_colors import MakeColors\r\nprint(\"Supports colors:\", MakeColors.supports_color())\r\n```\r\n\r\n```python\r\ndef test_all_colors():\r\n \"\"\"Test all available colors\"\"\"\r\n colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']\r\n light_colors = [f'light{color}' for color in colors if color != 'black'] + ['lightgrey']\r\n \r\n print(\"=== Standard Colors ===\")\r\n for color in colors:\r\n print(make_colors(f\" {color.ljust(10)}\", color, \"black\"))\r\n \r\n print(\"\\n=== Light Colors ===\")\r\n for color in light_colors:\r\n print(make_colors(f\" {color.ljust(15)}\", color, \"black\"))\r\n\r\n# Run the test\r\ntest_all_colors()\r\n\r\n---\r\n\r\n## \ud83c\udfaf Best Practices\r\n\r\n1. **Always check color support** `MakeColors.supports_color()` before production use\r\n2. **Provide fallbacks** for environments without color support (e.g. plain text when disabled)\r\n3. **Use env vars for CI/CD or logging**\r\n4. **Choose contrasting colors** for better readability\r\n5. **Test on multiple OSes/terminals/platforms** to ensure compatibility\r\n\r\n```python\r\nfrom make_colors import make_colors, MakeColors\r\n\r\ndef safe_print(text, fg=\"white\", bg=None):\r\n \"\"\"Safely print colored text with fallback\"\"\"\r\n if MakeColors.supports_color():\r\n print(make_colors(text, fg, bg))\r\n else:\r\n print(f\"[{fg.upper()}] {text}\")\r\n\r\n# Usage\r\nsafe_print(\"This works everywhere!\", \"green\")\r\n```\r\n\r\n## \ud83e\uddd9 Magick\r\n```python\r\n \r\n from make_colors import *\r\n\r\n print(red(\"Error!\"))\r\n print(bl(\"Im Blue\"))\r\n print(green_on_black(\"Success\"))\r\n\r\n # Abbreviation\r\n print(w_bl(\"White on Blue\")) # white on blue\r\n print(r_w(\"Red on White\")) # red on white\r\n print(g_b(\"Green on Black\")) # green on black\r\n print(lb_b(\"Light Blue on Black\"))\r\n\r\n color = Colors('red', 'white')\r\n print(color(\"White on Red\"))\r\n color = Color('white', 'red')\r\n print(color(\"TEST\"))\r\n\r\n\r\n # Try and see what happened \ud83d\udc4f \ud83d\ude04\r\n```\r\n\r\n---\r\n\r\n## \u26a0\ufe0f Error Handling\r\n\r\n* Invalid color \u2192 falls back to white on black\r\n* Unknown attribute \u2192 ignored silently\r\n* Raise `MakeColorsError` for invalid color names (if strict)\r\n* Raise `MakeColorsWarning` for warnings\r\n\r\n```python\r\ntry:\r\n print(make_colors(\"Oops\", \"notacolor\"))\r\nexcept Exception as e:\r\n print(\"Handled:\", e)\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udcca Performance\r\n\r\n* Traditional call: \\~0.00001s per render\r\n* Rich markup parsing: slightly slower (\\~+10\u201315%)\r\n* Suitable for **high-frequency logging**\r\n\r\n---\r\n\r\n## \ud83d\udcd1 Quick Reference\r\n\r\n* \u2705 Single color: `[red]text[/]`\r\n* \u2705 With background: `[white on red]text[/]`\r\n* \u2705 With style: `[bold green]text[/]`\r\n* \u2705 Combined: `[bold white on red]ALERT[/]`\r\n* \u2705 Multiple tags: `[cyan]Info[/] [red]Error[/]`\r\n\r\n---\r\n\r\n## \ud83e\udd1d Contributing\r\n\r\nPRs welcome! Open issues for feature requests or bugs.\r\nContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\r\n\r\n---\r\n\r\n## \ud83d\udcc4 License\r\n\r\nLicensed under the **MIT License**. See [LICENSE](LICENSE).\r\n\r\n---\r\n\r\n## \ud83d\udc68\u200d\ud83d\udcbb Author\r\n\r\n**Hadi Cahyadi**\r\n\ud83d\udce7 [cumulus13@gmail.com](mailto:cumulus13@gmail.com)\r\n\r\n[](https://www.buymeacoffee.com/cumulus13)\r\n\r\n[](https://ko-fi.com/cumulus13)\r\n\r\n[Support me on Patreon](https://www.patreon.com/cumulus13)\r\n\r\n---\r\n\r\n\u2728 Made with \u2764\ufe0f by Hadi Cahyadi for colorful terminal experiences!\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple, powerful, and cross-platform Python library for adding colors, styles, and rich markup support to your terminal output. Optimized for **Windows 10+**, Linux, and macOS.",
"version": "3.48.3",
"project_urls": {
"Code": "https://github.com/cumulus13/make_colors",
"Documentation": "https://github.com/cumulus13/make_colors",
"Homepage": "https://github.com/cumulus13/make_colors",
"Issue tracker": "https://github.com/cumulus13/make_colors/issues"
},
"split_keywords": [
"color",
" terminal",
" console",
" ansi",
" text",
" colorize",
" cli",
" markup",
" rich_markup"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "866800f8b5ec1d1feba849185479b1e42fdac92a1f5f6f01b7eda0eb7fef2b28",
"md5": "bfe64ae06b3f446f068a968ef387f359",
"sha256": "cf9917ff6eb2815f413fc0d450b91e71489236a17800595a0a85314dd3bad13d"
},
"downloads": -1,
"filename": "make_colors-3.48.3-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "bfe64ae06b3f446f068a968ef387f359",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=2.7",
"size": 53066,
"upload_time": "2025-10-09T09:34:17",
"upload_time_iso_8601": "2025-10-09T09:34:17.876721Z",
"url": "https://files.pythonhosted.org/packages/86/68/00f8b5ec1d1feba849185479b1e42fdac92a1f5f6f01b7eda0eb7fef2b28/make_colors-3.48.3-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5ec98f522cb3e3e2222039140a0f3d14b1d311fdd995c9478fd83a945256645a",
"md5": "e5ca520cd9eca82093339ee68c5ebede",
"sha256": "7d99d45e826d1bf0aba49d46759ca5cf5a0a0f798bc24ab6525fc9a7deabca98"
},
"downloads": -1,
"filename": "make_colors-3.48.3.tar.gz",
"has_sig": false,
"md5_digest": "e5ca520cd9eca82093339ee68c5ebede",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=2.7",
"size": 36384,
"upload_time": "2025-10-09T09:34:22",
"upload_time_iso_8601": "2025-10-09T09:34:22.918591Z",
"url": "https://files.pythonhosted.org/packages/5e/c9/8f522cb3e3e2222039140a0f3d14b1d311fdd995c9478fd83a945256645a/make_colors-3.48.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-09 09:34:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cumulus13",
"github_project": "make_colors",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "make-colors"
}