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.1.tar.gz (5.7 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.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: colrs-0.1.1.tar.gz
  • Upload date:
  • Size: 5.7 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.1.tar.gz
Algorithm Hash digest
SHA256 fe0685ae035f4ead6d9e545c726fd56481448154d63ca60c26a306ffabeebdf2
MD5 5afa7526f2a389632dca13e3274e1086
BLAKE2b-256 b7a5d48793c47c3b8806bc7f4a587ba4a6acc6697c8e2368497685dc432b147b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: colrs-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb51150bbe444690a8c358d70c610d3f19fc6f5e1147c6a864960b317ddb7b5e
MD5 76315750c74967921995010af0a1ba03
BLAKE2b-256 d6d84cb0ca5ccaa7772daa72e54bbcf6541437541bafa12d008f5876ddd781a5

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