Skip to content

lukaskubis/crayon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

crayon

PyPI PyPI PyPI License

Imgur

Minimal python utility for styling your terminal output. The idea here is to use a wrapper to add styling options for print function. Let me explain...

pip install crayon

To test your terminal output just launch the crayon module

How-to

Define your preferred style as a dictionary

from crayon import *

my_style = dict(prefix='* ', # prefix
                color= dict(fg=rgb(5, 3, 1), bg=BLUE),
                style= dict(bold=True),
                indent=4,

                # you can also set 'print' function kwargs
                sep=' *\n',
                end=' *\n***\n')

Call function printout the same way as print. If you used print function keywords, they get passed to it as usual. Example:

printout(False, "Hello", 4, **my_style)

Colors

The default 16 terminal colors are set as constants for easy access.

# System color name constants.
COLORS = (
    BLACK,
    RED,
    GREEN,
    YELLOW,
    BLUE,
    MAGENTA,
    CYAN,
    LIGHT_GRAY,
    DARK_GRAY,
    BRIGHT_RED,
    BRIGHT_GREEN,
    BRIGHT_YELLOW,
    BRIGHT_BLUE,
    BRIGHT_MAGENTA,
    BRIGHT_CYAN,
    WHITE,
) = range(16)

The grayscale supports 24 values.

my_grayscale_color = gray(10) # (0 - 23)

The rest is set by rgb function.

my_rgb_color = rgb(5, 3, 1) # (0 - 5) scale to accomodate 216 colors

That's all 256 colors supported by most modern terminals.

color_config = {'fg':my_grayscale_color, 'bg':my_rgb_color}
printout(my_text, color=color_config)

Styles

Set up a style config the same way as color config, this one is simple.

style_config = {'bold':True, 'underline':True} # True/False for each, False by default

Combine these configs into one complete style configuration. Feel free to add print function keyword arguments as well.

config = {'color':color_config, 'style':style_config, 'end':'\n***\n'}

# color and style config gets applied for every thing in things
# 'print' function kwargs work as usual
printout(*things, **config)

Todos:

  • conditional styling? (v1.0)
  • fix some name conflicts
  • proper project description and documentation

Releases

No releases published

Packages

No packages published

Languages