Skip to main content

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.

Release files for prettystring 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prettystring 0.1.1
File Size Uploaded
prettystring-0.1.1.tar.gz 5.2 kB Details

Release files / prettystring-0.1.1.tar.gz

Download URL prettystring-0.1.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
27b7e1599326e24c9615ad8f4120814d315bee87293e3b3728ee1a6da58e8224
BLAKE2b-256 checksum
How to use checksums
e5355895e9f5f1f32cdab4618b560c83849eac738eab94ba97cf5eb8b199de55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page