Skip to main content

Pythonic cross-platform colored terminal text [support 16/256 colors]

Project description

Sheen:

Pythonic cross-platform colored terminal text [support 16/256 colors]

Let color be your new dimension to integrate more imagination.

Quick Learn

Come to try the code below, in your IDLE

>>> from sheen import Str
>>>
>>> Str.red('render font color with lowercase')
>>> Str.RED('render background color with uppercase')
>>> Str.Underline('render style with capital')
>>> 
>>> Str.red.BLUE('joint rendering with dot')
>>> Str.BLUE.red("yes! it's free, no order restrain")
>>> Str.cyan.LIGHTBLUE.Underline('esay to lean, ease to use')
>>>
>>> Str.red("You can use it like builtin 'str'").split(' ')
>>> text = Str.lightcyan.Twinkle("Let us integrate more imagination")
>>> text.replace('Let us', Str.lightred('pip install sheen, to'))
>>> Str.LIGHTWHITE('@!$#!&*&simplify for human! i am sheen!#@$#%^&').title().strip('!@#$%^&*')

Simple is better than complex. flat is better than nested. Readability counts.
-- excerpt from the zen of python

Str Type Supported:

Str Type Supported Attribute Chain
Font Colorblackredgreenyellow
lightblacklightredlightgreenlightyellow
bluemagentacyanwhite
lightbluelightmagentalightcyanlightwhite
Background ColorBLACKREDGREENYELLOW
BLUEMAGENTACYANWHITE
LIGHTBLACKLIGHTREDLIGHTGREENLIGHTYELLOW
LIGHTBLUELIGHTMAGENTALIGHTCYANLIGHTWHITE
Style TypeBoldItalicUnderlineTwinkle

Installation

To install sheen, simply use pip:

$ pip install sheen
$ python -m sheen

If it's successfully installed, it will be as shown below.

It's a simple way to get tutorial, you don't need to come here every time
when you forget the usage of sheen

Learn More

How to display with 256 colors

Your can choose the color that your like with 'Color' type

>>> from sheen import Str, Color
>>> Color.palette()  # Reference color code
>>>
>>> Color.rgb(222)('render font color with rgb')
>>> Color.RGB(123)('render background color with RGB')
>>> 
>>> Color.rgb([255,200,190])('render font color with rgb')
>>> Color.RGB([150,120,250])('render background color with RGB')
>>>
>>> DIYcolor = Color.rgb(222) | Color.RGB(123) | Str.Underline
>>> DIYcolor("It's my color style")
>>>
>>> text = Str.Underline('Use slice to modification color')
>>> text[:] = Color.rgb(222)
>>> text[-3:-5] = Color.RGB(123)
>>> text

It's said that 256 colors can be valid in the terminal
but maybe invalid in the IDE

How to config Multicolored logging

Sheen has been build-in scheme, which can prints different colored logs based on log level:

As you can see, sheen only takes 5 lines to complete
the configuration of the Multicolored logging

You can design 'Formatter', to get color scheme which belong to yourself

import logging
from sheen import Str, ColoredHandler

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


handle = ColoredHandler()
handle.setFormatter({
    logging.DEBUG: logging.Formatter(fmt=str(Str.blue('%(asctime)s - %(levelname)s | %(message)s')), datefmt='%Y-%m-%d'),
    logging.INFO: Str.magenta('%(asctime)s - %(levelname)s | %(message)s'),
})
logger.addHandler(handle)

logger.debug('debug')
logger.info('info')
logger.warning('warning')
logger.error('error')
logger.critical('critical')

Take it easy, it will be use after rendered as 'str' type
without affecting the logging output speed

How to get the best performance

Sheen was born for convenience, when you want the fastest, there is a way.

>>> from sheen import Str, Color
>>> str(Str.cyan.BLUE('... content ...'))
'\x1b[36;44m... content ...\x1b[0m'
>>>

Don't forget to 'import sheen', It's necessary on windows.
-- Windows 10 is default closed ANSI Escape Code

FAQ

  • :speech_balloon: Why not support python2.7

    Python 2.7 will retire in 2020 https://pythonclock.org/, Many libraries already or will to give up compatibility 2.7, such as NumPy, Pandas, Ipython, Matplotlib ...

  • :speech_balloon: Why not support version below Windows 10

    Windows support ANSI Escape Code start with win10, this gives the possibility to use ANSI to display colors for sheen. the version below Windows 10 will retire in future, just like python2.7

  • :speech_balloon: How to get the best running performance

    Render to ANSI Escape Code, and then copy it into your code, no faster than this. but in most cases you needn't to do this

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

sheen-0.1.2.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

sheen-0.1.2-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file sheen-0.1.2.tar.gz.

File metadata

  • Download URL: sheen-0.1.2.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for sheen-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bf06acc95d9c8ec72b9a2cbac48b14dcd40c2688aaf981a582a9b59804fcfed2
MD5 8b5ee8ef0d1e9b28bb3aa4d4b45b29a0
BLAKE2b-256 74379d73f77aa6e4e492a0d1279011822fb8a6941aa69ab4fcf79ae1f7415168

See more details on using hashes here.

File details

Details for the file sheen-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sheen-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for sheen-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4b24179c71c26fb4036afffa11c72719c927d307ac0b284a0d62eb4e828c1e51
MD5 cb0563fe63efd1962957ecd6d60a466f
BLAKE2b-256 bf1e2a7df403ba237be17eeab327f71baa32c2beffe0cec6416835a0274450b6

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