Skip to main content

Easy terminal colors for linux, with chainable methods.

Project description

A python module for using terminal colors in linux. It contains a simple color function that accepts style and color names, and outputs a string with escape codes, but also has all colors and styles as chainable methods on the Colr object.

Examples:

Simple:

from colr import color
print(color('Hello world.', fore='red', style='bright'))

Chainable:

from colr import Colr as C
print(
    C()
    .bright().red('Hello ')
    .normal().blue('World')
)

# Background colors start with 'bg', and AttributeError will be raised on
# invalid method names.
print(C('Hello ', fore='red').bgwhite().blue('World'))

Examples (256 Colors):

Simple:

from colr import color
# Invalid color names/numbers raise a ValueError.
print(color('Hello world', fore=125, back=80))

Chainable:

from colr import Colr as C
# Foreground colors start with 'f256_'
# Background colors start with 'b256_'
print(C().f256_125().b256_80('Hello World'))

Notes:

Windows is not supported yet, but I’m working on it. In the past, I used a simple color() function because I’m not fond of the string concatenation style that other libraries use. The ‘clor’ javascript library uses method chaining because that style suits javascript, but I wanted to make it available to Python also, at least as an option.

The reset code is appended to all text. If no text is given, no reset code is appended. This makes it possible to build background colors and styles, but also have separate styles for separate pieces of text.

Colr objects are callable, and when called as a function will append text (also with optional color kwargs).

This library may be a little too flexible, and that may change:

from colr import Colr as C
warnmsg = lambda s: C('warning', 'red').join('[', ']')(' ').green(s)
print(warnmsg('The roof is on fire again.'))
warning

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

Colr-0.0.3-1.tar.gz (7.4 kB view details)

Uploaded Source

File details

Details for the file Colr-0.0.3-1.tar.gz.

File metadata

  • Download URL: Colr-0.0.3-1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Colr-0.0.3-1.tar.gz
Algorithm Hash digest
SHA256 dd0557590eb50d60359c5f5b4a8fe88f1e8f3e93bfac3dacb8e9f3d7f0262d98
MD5 d31af8a9296153b2256c170da9096dff
BLAKE2b-256 2042969c072535b658323286324ff95ad1d2fea6a7f3c86fbd4c1db63d8ac3bc

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