Giter Site home page Giter Site logo

crayon's Introduction

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

crayon's People

Contributors

lukaskubis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.