python-click/examples/colors/colors.py

45 lines
1 KiB
Python
Raw Normal View History

2014-10-16 20:40:34 +02:00
import click
2020-07-21 08:23:42 +02:00
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",
)
2014-10-16 20:40:34 +02:00
@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:
2020-07-21 08:23:42 +02:00
click.echo(click.style("I am colored {}".format(color), fg=color))
2014-10-16 20:40:34 +02:00
for color in all_colors:
2020-07-21 08:23:42 +02:00
click.echo(
click.style("I am colored {} and bold".format(color), fg=color, bold=True)
)
2014-10-16 20:40:34 +02:00
for color in all_colors:
2020-07-21 08:23:42 +02:00
click.echo(
click.style("I am reverse colored {}".format(color), fg=color, reverse=True)
)
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
click.echo(click.style("I am blinking", blink=True))
click.echo(click.style("I am underlined", underline=True))