Skip to content

philer/shellcolors

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

shellcolors.py

Style your commandline output from python scripts

How it works:

  1. Embed XML-like tags into a string, for example "This is <green>an example</green>."
  2. The recognized tags will be converted to escaped ANSI/VT100 control sequences.
    They look like this: "This is \x1b[32man example\x1b[39m.". If you print() this it'll turn into color.

Usage:

import shellcolors

# basic
raw = "some <green>string</green> with <red><bold>styling</bold></red>"
styled = shellcolors.compile(raw)
print(styled)

# style an entire string
styled = shellcolors.style("yellow", "bold", "This string will be yellow and bold.")
print(styled)

# style/compile a string and print it directly
shellcolors.cprint("some <green>string</green> with <red><bold>styling</bold></red>")
shellcolors.sprint("yellow", "bold", "This string will be yellow and bold.")

# all colors and styles are available as a function
print(shellcolors.blue("This string will be blue"))

On my urxvt terminal the output of the above looks like this:

screenshot

Requirements

Available colors and styles

All styles available through ANSI/VT100 Control sequences can be used, including a few non-standard ones that are commonly supported by terminal emulators.

  • Colors:
    • default
    • black, dark_grey, light_grey, white
    • red, green, yellow, blue, purple, cyan
    • light_red, light_green, light_yellow, light_blue, light_purple, light_cyan
  • Background colors: Same as foreground with a bg_ prefix (e.g. bg_dark_grey)
  • Styles: (some with aliases)
    • bold = bright = b = strong
    • italic = i = em
    • underline = underlined = u
    • strikethrough = s
    • invert = reverse
    • dim
    • hidden
    • blink (please don't use it…)

About

Simple python module for colorizing commandline output.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages