Skip to main content

Colorful worry-free console applications for Linux, Mac OS X, and Windows.

Project description

Yet another ANSI color text library for Python. Provides “auto colors” for dark/light terminals. Works on Linux, OS X, and Windows. For Windows support you just need to call Windows.enable() in your application.

On Linux/OS X autocolors are toggled by calling set_light_background() and set_dark_background(). On Windows this can be done automatically if you call Windows.enable(auto_colors=True).

In Python2.x this library subclasses unicode, while on Python3.x it subclasses str.

  • Python 2.6, 2.7, 3.3, and 3.4 supported on Linux and OS X.

  • Python 2.7, 3.3, and 3.4 supported on Windows (both 32 and 64 bit versions of Python).

Tested on Windows XP and Windows 10 technical preview.

Build Status Windows Build Status Coverage Status Latest Version Downloads

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

  • autobgblack

  • autobgred

  • autobggreen

  • autobgyellow

  • autobgblue

  • autobgmagenta

  • autobgcyan

  • autobgwhite

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.1.2

  • Maintaining Color type through .encode() and .decode() chains.

1.1.1

  • Fixed Python 2.7 64-bit original colors bug on Windows.

  • Fixed resetting colors when reset_atexit is True.

  • Improved sorting of list_tags().

1.1.0

  • Added native Windows support and automatic background colors.

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.1.2.tar.gz (13.1 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for colorclass-1.1.2.tar.gz
Algorithm Hash digest
SHA256 00e0ee013674487f7eefcfe0aebbcde93781240e3d9f31e74ce78660dfb93e13
MD5 d045675bd178c8e6fd3dcd0b992bdac4
BLAKE2b-256 67fe88fbc158f44a36e59f6590ccdb420c01fe2ee0a6dd5017648d5570aac6ac

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