diff options
author | Armin Ronacher <armin.ronacher@active-4.com> | 2014-05-27 20:59:50 +0600 |
---|---|---|
committer | Armin Ronacher <armin.ronacher@active-4.com> | 2014-05-27 20:59:50 +0600 |
commit | f516eeecf79be6ed51a064e99f01a34a4aec7a75 (patch) | |
tree | d456bd485a7cd6e8de2573d67fe5a01a116ed132 /examples/termui | |
parent | d27f3a62c5c65779b58bc618e72b50c59374942f (diff) | |
download | click-f516eeecf79be6ed51a064e99f01a34a4aec7a75.tar.gz |
Added style helpers and added deeper ansi color support. Colorama now optional.
Diffstat (limited to 'examples/termui')
-rw-r--r-- | examples/termui/setup.py | 1 | ||||
-rw-r--r-- | examples/termui/termui.py | 17 |
2 files changed, 8 insertions, 10 deletions
diff --git a/examples/termui/setup.py b/examples/termui/setup.py index 323cf28..c4a75dd 100644 --- a/examples/termui/setup.py +++ b/examples/termui/setup.py @@ -7,6 +7,7 @@ setup( include_package_data=True, install_requires=[ 'Click', + # Colorama is only required for windows. 'colorama', ], entry_points=''' diff --git a/examples/termui/termui.py b/examples/termui/termui.py index 916522f..13bbf38 100644 --- a/examples/termui/termui.py +++ b/examples/termui/termui.py @@ -2,7 +2,6 @@ import click import time import random -from colorama import Fore try: range_type = xrange @@ -19,7 +18,9 @@ def cli(): @cli.command() def colordemo(): """Demonstrates ANSI color support.""" - click.echo(Fore.YELLOW + 'Hello World!' + Fore.RESET) + for color in 'red', 'green', 'blue': + click.echo(click.style('I am colored %s' % color, fg=color)) + click.echo(click.style('I am background colored %s' % color, bg=color)) @cli.command() @@ -27,11 +28,7 @@ def pager(): """Demonstrates using the pager.""" lines = [] for x in xrange(200): - lines.append('%s%d%s. Hello World!' % ( - Fore.GREEN, - x, - Fore.RESET - )) + lines.append('%s. Hello World!' % click.style(str(x), fg='green')) click.echo_via_pager('\n'.join(lines)) @@ -51,7 +48,7 @@ def progress(count): yield item with click.progressbar(items, label='Processing user accounts', - fill_char=Fore.GREEN + '#' + Fore.RESET) as bar: + fill_char=click.style('#', fg='green')) as bar: for item in bar: process_slowly(item) @@ -60,14 +57,14 @@ def progress(count): return 'Item #%d' % item with click.progressbar(filter(items), label='Committing transaction', - fill_char=Fore.YELLOW + '#' + Fore.RESET, + fill_char=click.style('#', fg='yellow'), item_show_func=show_item) as bar: for item in bar: process_slowly(item) with click.progressbar(length=count, label='Counting', bar_template='%(label)s %(bar)s | %(info)s', - fill_char=Fore.BLUE + u'█' + Fore.RESET, + fill_char=click.style(u'█', fg='cyan'), empty_char=' ') as bar: for item in bar: process_slowly(item) |