Skip to main content

Terminal colors made easy!

Project description

Python Easy Color

Color output in python2/3 made easy!

Description

Make python color ouput easy in UNIX terminals that support ANSI sequences.

Installation

pip install easycolor

Documentation

Check the documentation at: (http://easycolor.readthedocs.io/en/latest/) also available at: (https://georgetg.github.io/easycolor/)

Source Code

Check at github: (https://github.com/GeorgeTG/easycolor)

License

Copyright George T. Gougoudis 2016. BSD 3-Clause license; see LICENSE file.

Basic usage

To wrap text, the wrap function must be imported.

from easycolor.style import wrap as _w

The text is then wrapped as easy as

# wrap text, appends a style-reset
print(_w('yellow on red', fg='yellow', bg='red'))
print('normal text')

To compile a style, the make_style function is used:

from easycolor.style import make_style, RESET

Example:

# define some styles
black_on_white = make_style(fg='black', bg='white')
# we have to reset the background here
red_bold = make_style(fg='red', bg='reset', opt='bold')
# An options reset is only possible with a total reset
# we can however negate an option to remove it('!option').
green_bold_underline = make_style(fg='green', opt=('!bold', 'underline'))

print(black_on_white + 'Black on white' + red_bold + 'Red bold' +
      green_bold_underline + 'Green not bold underline' + RESET)

Note: For advanced formatting use the easycolor.parser module.

Advanced usage

First obtain an instance

from easycolor.parser import ColorParser
parser = ColorParser()

Then for printing

cprint = parser.cprint
# Add rainbow colors!
cprint("""<f:red>r<f:yellow>ai<f:green>nb<f:blue>o<f:magenta>w"""
       """</f>o</f>bn</f>ia</f>r</f>""")
# complex foreground - background
cprint("""<f:red,b:yellow>red on yellow</b>just red<b:black>red on black!"""
       """<f:green>green on black</f>again red on black</f,b>normal""")

Parse a format string for a colored logger, for later use

INFO = parser.parse("[<f:cyan>INFO</f>] <o:bold>{}")
print(INFO.format('Some info..'))

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easycolor-0.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easycolor-0.1-py2.py3-none-any.whl (7.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file easycolor-0.1.tar.gz.

File metadata

  • Download URL: easycolor-0.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for easycolor-0.1.tar.gz
Algorithm Hash digest
SHA256 d00eeefad954946a1118c8042a69713c68942b8d7c6e1ec2ed8da018888072a9
MD5 5e02d553d35726b8ff6ebe427cbb6121
BLAKE2b-256 684c8d4bc46b59006daec8f185216e089138c7e098d778a833d215aebc9a948c

See more details on using hashes here.

File details

Details for the file easycolor-0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for easycolor-0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e6cf9fa1863f2129e267a3f4e24c90898fe8da6618294c78565ae7f17d1b4463
MD5 cd7df457fb2b369a50d8ed537736e9a9
BLAKE2b-256 3cbad2ef8c639e49e41c7c2579bbac8a65dcd542419eeebdc8afc6be5016ea3f

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