Skip to main content

A simple and elegant Python library for terminal text coloring.

Project description

colorara 🎨

A simple, elegant, and easy-to-use Python library to add color to your terminal text and backgrounds.

Features

  • Simple API: Color your text with zero hassle.
  • Cross-Platform: Works on Windows, macOS, and Linux thanks to colorama.
  • Inline Tag Coloring: Color specific words within a string using simple tags like <green>word</>.
  • Colored User Input: Control the color of the user's typed text in input() prompts.
  • "Magic": An optional mode to make the built-in print() and input() color-aware.
  • Lightweight: Has only one dependency (colorama) for cross-platform support.

Installation

First, navigate to the colorara project directory. Then, install it using pip:

pip install .

After installation, you can import it in any Python script on your system.

Usage

colorara is designed for flexibility and ease of use.


cprint() and Inline Coloring

The cprint() function is your main tool for printing. It supports both coloring the entire line and coloring specific parts of a string using tags.

Syntax: <color_name>text</> or <text_color,bg_color>text</>

from colorara import cprint

# Overall coloring (like before)
cprint("This entire line is green.", color="green")

# --- Inline Tag Coloring ---
# Color a specific word
cprint("Status: <green>OK</>")

# Use multiple colors in one line
cprint("Results: <green>SUCCESS</>, Warnings: <yellow>3</>, Errors: <red>0</>")

# You can also color backgrounds
cprint("System State: <white,bg_green>ONLINE</>") 
cprint("Alert: <black,bg_yellow>CHECK CONFIG</>")

# If you provide a `color` argument with tags, it is ignored
cprint("The tag <green>always</> wins.", color="red") # "always" will be green

cinput() and Colored User Input

Use cinput() to get user input with a colored prompt and even colored user-typed text.

It accepts a new argument inp_color. If you provide it, the user's typing will be in that color. If you don't, the user's typing will have the same color as the prompt.

from colorara import cinput

# The user's typed text will be cyan, just like the prompt
name = cinput("Enter your name: ", color="cyan")
print(f"Hello, {name}!")

# The prompt will be yellow, but the user's typing will be blue
age = cinput("Enter your age: ", color="yellow", inp_color="blue")
print(f"You are {age} years old.")

Magic ✨

This mode is for maximum convenience. By calling magic() once, colorara patches the built-in print() and input() functions, giving them all the powers of cprint and cinput.

⚠️ Warning: This modifies Python's built-in functions and might cause conflicts if another library tries to do the same. Use it with caution.

from colorara import magic, revert

# Activate magic
magic()

# The built-in print now understands tags!
print("Magic <magenta>print</> supports tags too!")
print("Status: <green>OK</>, Mode: <cyan,bg_black>MAGIC</>")

# The magic input also supports `inp_color`
food = input("Favorite food (prompt is red, typing is green)? ", color="red", inp_color="green")
print(f"You like {food}!")

# You can revert the changes if needed
revert()

# This print will be normal again
print("Back to normal.")

Available Colors

You can use the following color names for both color and bg_color:

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

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

colrs-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

colrs-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file colrs-0.1.0.tar.gz.

File metadata

  • Download URL: colrs-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for colrs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1abf81592514a1c91a54885bb04ab7466c4b1bb101002d93127b28a3354d5f7f
MD5 53077656e0f1466e15c87851a00212a3
BLAKE2b-256 9ef80af7215466d13b740dc234c6551532e650fade46038df96c8cff0c131d44

See more details on using hashes here.

File details

Details for the file colrs-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: colrs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for colrs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ca4ad6d2e1864793381019151e8bdd74b238f5a49ad5dc32572fe1f2fa59064
MD5 30fadad4c9743b26d2ae85532e513bb3
BLAKE2b-256 9ce6fca6170871686a59c62c04588f732b71c16f7cba0f31c34605a9df744dbc

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