Skip to main content

Build ANSI color encoded strings with ease.

Project description

prettystring

https://travis-ci.org/robolivable/prettystring.svg?branch=master

Use prettystring to build colorful strings for more engaging output.

Prettystrings are conveniently encoded with the proper ANSI color codes based on the colors you specify for them.

Installation

Install using pip:

pip install prettystring

Usage

As straight forward as you may think:

>>> from prettystring import prettystring as pstr
>>> colorful = pstr('sweet!')
>>> colorful.__str__()
'\x1b[;39;49msweet!\x1b[0m'

Prettystrings are initialized with default ANSI code values. sweet! should be in default colors. Paint it with paint():

>>> colorful.paint(pstr.blue)
>>> colorful.__str__()
'\x1b[;34;49msweet!\x1b[0m'
>>> print colorful
sweet!

The value of colorful will show up blue when print is called on it.

You can also initialize prettystrings with a style:

>>> stylish = pstr('the answer is 42', pstr.blink, pstr.green, pstr.bgblue)
>>> stylish.__str__()
'\x1b[5;32;44mthe answer is 42\x1b[0m'
>>> print stylish
the answer is 42

You can even format:

>>> pstr('Hello {}!').paint(pstr.red).format(pstr('world').paint(pstr.blue))
'\x1b[;31;49mHello \x1b[;34;49mworld\x1b[0m\x1b[;31;49m!\x1b[0m'

Note that format returns a regular string. This is a known limitation, and is being worked on.

Prettystring Enums

Use these enum values with the paint() method to apply color and formatting to prettystrings.

Note that you can only apply one style, one color, and one background color at a time (no mixing colors [yet]).

Styles (Formatting)

prettystring.styledefault
prettystring.bold
prettystring.dim
prettystring.underline
prettystring.blink
prettystring.invert
prettystring.hidden

Colors

prettystring.default
prettystring.black
prettystring.red
prettystring.green
prettystring.yellow
prettystring.blue
prettystring.magenta
prettystring.cyan
prettystring.light
prettystring.dark

Light colors

prettystring.lred
prettystring.lgreen
prettystring.lyellow
prettystring.lblue
prettystring.lmagenta
prettystring.lcyan
prettystring.white

Background colors

prettystring.bgdefault
prettystring.bgblack
prettystring.bgred
prettystring.bggreen
prettystring.bgyellow
prettystring.bgblue
prettystring.bgmagenta
prettystring.bgcyan
prettystring.bglight
prettystring.bgdark

Light background colors

prettystring.bglred
prettystring.bglgreen
prettystring.bglyellow
prettystring.bglblue
prettystring.bglmagenta
prettystring.bglcyan
prettystring.bgwhite

Compatibility

Prettystring is sure to work in most Unix based environments. Official compatibility tests/upgrades are soon to come.

Contribution

Feel free to make prettystring better by submitting a pull request. I will review your submission as soon as possible.

License

This software is distributed under the MIT License. See LICENSE.md for details.

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

prettystring-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file prettystring-0.1.1.tar.gz.

File metadata

  • Download URL: prettystring-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for prettystring-0.1.1.tar.gz
Algorithm Hash digest
SHA256 27b7e1599326e24c9615ad8f4120814d315bee87293e3b3728ee1a6da58e8224
MD5 2785041e0ad4d77bc744e6c70d5308b8
BLAKE2b-256 e5355895e9f5f1f32cdab4618b560c83849eac738eab94ba97cf5eb8b199de55

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