mirror of
https://github.com/kennethreitz/clint.git
synced 2026-06-05 06:46:16 +00:00
Configurable progress bars :)
Argument changes.
This commit is contained in:
@@ -10,17 +10,26 @@ This module provides the progressbar functionality.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from .core import puts
|
||||
|
||||
import sys
|
||||
|
||||
BAR_TEMPLATE = '%s[%s%s] %i/%i\r'
|
||||
BAR_EMPTY_CHAR = '-'
|
||||
BAR_FILLED_CHAR = '='
|
||||
|
||||
def bar(it, prefix='', width=32, hide=False):
|
||||
DOTS_CHAR = '.'
|
||||
|
||||
|
||||
def bar(it, label='', width=32, hide=False):
|
||||
"""Progress iterator. Wrap your iterables with it."""
|
||||
count = len(it)
|
||||
if count:
|
||||
def _show(_i):
|
||||
x = int(width*_i/count)
|
||||
if not hide:
|
||||
sys.stdout.write("%s[%s%s] %i/%i\r" % (prefix, "="*x, "-"*(width-x), _i, count))
|
||||
puts(BAR_TEMPLATE % (
|
||||
label, BAR_FILLED_CHAR*x, BAR_EMPTY_CHAR*(width-x), _i, count), newline=False)
|
||||
sys.stdout.flush()
|
||||
|
||||
_show(0)
|
||||
@@ -32,12 +41,15 @@ def bar(it, prefix='', width=32, hide=False):
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def dots(it, prefix='', hide=False):
|
||||
def dots(it, label='', hide=False):
|
||||
"""Progress iterator. Prints a dot for each item being iterated"""
|
||||
count = len(it)
|
||||
|
||||
puts(label, newline=False)
|
||||
if count:
|
||||
def _show(_i):
|
||||
sys.stdout.write('.')
|
||||
# sys.stdout.write('.')
|
||||
puts(DOTS_CHAR, newline=False)
|
||||
|
||||
_show(0)
|
||||
for i, item in enumerate(it):
|
||||
|
||||
Reference in New Issue
Block a user