Skip to main content

A simple and elegant Python library for terminal text coloring.

Project description

colrs 🎨

A radically simple Python library for coloring your terminal output.

License: MIT

colrs takes a different approach to terminal coloring. Instead of wrapping your print statements in special functions, you activate it once, and your standard print and input functions become color-aware.


Philosophy

The core idea is absolute simplicity. No new function names to remember for printing. Just activate the magic and write your code as you normally would, but with added superpowers.

  • Activate: act()
  • Use print and input normally: Add colors with tags or keyword arguments.
  • Deactivate: unact()
  • Show Animations: loading()

This is the core public API, designed for simplicity and power.

Installation

To install the library:

pip install colrs

How to Use

The usage is designed to be as intuitive as possible. You import act and unact, and wrap the code you want to be color-aware.

Basic Example

from colrs import act, unact

# This print is normal
print("This is default terminal text.")

# Activate the color patching
act()

# Now, print() and input() are super-powered!
print("This is a <green>green text</> using inline tags.")
print("This is red.", color="red")
print("This is blue on a yellow background.", color="blue", bg_color="yellow")

name = input("What's your name? ", color="cyan", inp_color="magenta")
print(f"Hello, {name}!")

# It's good practice to deactivate when you're done
unact()

print("And we're back to normal.")

Using print() with act()

Once act() is called, print() can accept two new keyword arguments: color and bg_color.

More powerfully, you can use inline tags for fine-grained control.

act()

# Simple tags
print("<red>This will be red.</red>") # The closing tag is optional

# Nested tags
print("<yellow>This is yellow with <blue>blue text</blue> inside.</yellow>")

# Background colors
print("<white,bg_red> White text on a red background. </>") # </> resets all

unact()

Using input() with act()

The patched input() can color three things separately:

  1. The prompt text (color and bg_color arguments, or tags).
  2. The text the user types (inp_color argument).
act()

# The prompt will be yellow, and the user's typing will be cyan
username = input("Enter username: ", color="yellow", inp_color="cyan")

# You can also use tags in the prompt
password = input("<red>Enter password:</red> ", inp_color="red")

unact()

Why colrs?

If you want a coloring library that "just works" in the background without forcing you to change your coding habits, colrs is for you. It's designed for scripts and applications where you want to enable colors globally with minimal code changes.

License

This project is licensed under the MIT License.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: colrs-0.1.7.tar.gz
  • Upload date:
  • Size: 9.6 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.7.tar.gz
Algorithm Hash digest
SHA256 9c2f17f1a3a9e62adde256bc74e3a6ee8cd72120fe666dd60f76b0c126571ed1
MD5 8f1de2167b53efd6f37b77e53628474f
BLAKE2b-256 51aca0a4ec48e9f1e08dc8b1cbd5a129c4d51af1ff0a78ae9c6aeab5ae63f795

See more details on using hashes here.

File details

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

File metadata

  • Download URL: colrs-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 10.9 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 34b2db5f4df959931411724e93508354da0b9c4015a115406ed550513adfd21c
MD5 0b7c1aeeca0487486059a9c6c3b0b537
BLAKE2b-256 2d4b4b77c8248c0ca5efff8cf819dee9d3fbacf7a52f928e8ff6b17f7764a359

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