Giter Club home page Giter Club logo

python-terminal-color's Introduction

Python Terminal Color

image

Introduction

  1. This is a drop-in library for print colorized output in terminal.
  2. It has no pypi package, which means you can't install it through pip.
  3. It is recommended to be used as a submodule of your own project, so that no dependency will be involved.
  4. color.py is Python 3 only and recommended to choose; color_compat.py is Python 2/3 compatible, only use it if you still struggle in the Python 2 morass.

Usage

Copy the color.py file to your project, then:

from yourproject import color

# 8 bit color
print(color.red('red') + color.green('green') + color.blue('blue'))
print(color.bold(color.yellow('bold yellow')) + color.underline(color.cyan('underline cyan')))
print(color.magenta_hl('magenta highlight'))

# xterm 256 color
print(color.bg256('A9D5DE', color.fg256('276F86', 'Info!')))
print(color.bg256('E0B4B4', color.fg256('912D2B', 'Warning!')))
print(color.hl256('10a3a3', 'Teal'))

Note:

  1. Every color function receives and returns string, so that the result could be used with any other strings, in any string formatting situation.
  2. If you pass a str type string, the color function will return a str. If you pass a bytes type string, the color function will return a bytes.
  3. Color functions could be composed together, like put red into bold, or put bg256 into fg256. xxx_hl and hl256 are mostly used independently.

API

function <color_function>(s)

Decorate string with specified color.

color_function is one of below function names:

Colors Background Highlight
black black_bg black_hl
red red_bg red_hl
green green_bg green_hl
yellow yellow_bg yellow_hl
blue blue_bg blue_hl
magenta magenta_bg magenta_hl
cyan cyan_bg cyan_hl
white white_bg white_hl

A color function with _bg suffix means it will set color as background. A color function with _hl suffix means it will set color as background, and change the foreground as well to make the word standout.

Parameters:

param str s

The input string

return

The decorated string

rtype

string

raises ValueError

if the message_body exceeds 160 characters

function <style_function>(s)

Decorate string with specified style.

style_function is one of below function names:

  • bold
  • italic
  • underline
  • strike
  • blink

Arguments and return are the same as color_function.

function <256_color_function>(hexrgb, s)

Decorate string with specified hex rgb color

256_color_function is one of below function names:

  • fg256: will set color as foreground.
  • bg256: will set color as background.
  • hl256: will highlight input with the color.

Parameters:

param str hexrgb

The hex rgb color string, accept length 3 and 6. eg: 555, 912D2B

param str s

The input string

return

The decorated string

rtype

string

raises ValueError

If the input string's length not equal to 3 or 6.

python-terminal-color's People

Contributors

reorx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

python-terminal-color's Issues

Add license

Hi, I'd like to use this in my project but it doesn't have a license. Would you consider publishing this under something like MIT?

Thanks,
Matthew

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.