Skip to content

Instantly share code, notes, and snippets.

@turing4ever
Last active January 7, 2019 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turing4ever/fdbd899d61b234fdcff9e50525589a47 to your computer and use it in GitHub Desktop.
Save turing4ever/fdbd899d61b234fdcff9e50525589a47 to your computer and use it in GitHub Desktop.
Use click to colorize cli output
import click
all_colors = 'black', 'red', 'green', 'yellow', 'blue', 'magenta', \
'cyan', 'white', 'bright_black', 'bright_red', \
'bright_green', 'bright_yellow', 'bright_blue', \
'bright_magenta', 'bright_cyan', 'bright_white'
@click.command()
def cli():
"""This script prints some colors. If colorama is installed this will
also work on Windows. It will also automatically remove all ANSI
styles if data is piped into a file.
Give it a try!
"""
for color in all_colors:
click.echo(click.style('I am colored %s' % color, fg=color))
for color in all_colors:
click.echo(click.style('I am colored %s and bold' % color,
fg=color, bold=True))
for color in all_colors:
click.echo(click.style('I am reverse colored %s' % color, fg=color,
reverse=True))
click.echo(click.style('I am blinking', blink=True))
click.echo(click.style('I am underlined', underline=True))
click.secho('hello from secho()', fg='red')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment