Skip to main content

Unicode class with automatic (light/dark background) terminal colors support.

Project description

Yet another ANSI color text library for Python. Provides “auto colors” for dark/light terminals.

In Python2.x this library subclasses unicode, while on Python3.x it subclasses str. colorclass is supported on Python 2.6, 2.7, 3.3, and 3.4.

Windows support effortlessly provided with the help of colorama. I didn’t have to change anything! Though only dark colors seem to work.

Build Status Coverage Status Latest Version Downloads Download format License

Quickstart

Install:

pip install colorclass

Example Implementation

Example Script Screenshot

Example Windows Screenshot

Source code for the example code is: example.py

Usage

Different colors are chosen using curly-bracket tags, such as {red}{/red}. For a list of available colors, call colorclass.list_tags().

The available “auto colors” tags are:

  • autoblack

  • autored

  • autogreen

  • autoyellow

  • autoblue

  • automagenta

  • autocyan

  • autowhite

Methods of Class instances try to return sane data, such as:

from colorclass import Color
color_string = Color('{red}Test{/red}')

color_string
u'\x1b[31mTest\x1b[39m'

len(color_string)
4

color_string.istitle()
True

There are also a couple of helper attributes for all Color instances:

color_string.value_colors
'\x1b[31mTest\x1b[39m'

color_string.value_no_colors
'Test'

Changelog

1.0.2

  • Added ability to disable/strip out all colors.

1.0.1

  • Fixed splitlines() method.

1.0.0

  • Initial release.

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

colorclass-1.0.2.tar.gz (6.4 kB view details)

Uploaded Source

File details

Details for the file colorclass-1.0.2.tar.gz.

File metadata

  • Download URL: colorclass-1.0.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for colorclass-1.0.2.tar.gz
Algorithm Hash digest
SHA256 b50bfb904789b5fc6bef04820d46fb39eb0943de5d439fb75e4020eb7b99021e
MD5 96b23cacba2d7828f922f2ad6cf46ed2
BLAKE2b-256 ca9ea562e93447c28bc6841fbb7906f2e6f8bf4fda229eeaac5cf6a0383dcbf7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page