Permalink
Browse files

Add a mill progress indicator to `progress.py`

I've created a progress indicator that outputs a "mill" and added it to
the `progress.py` file.

Very simple stuff but its more compact than the other progress bars and
it can be useful when using long labels.
  • Loading branch information...
1 parent 73a9cd8 commit a95e803268f298a4b7c7f9b64693b4f5507d9763 Alejandro Gómez committed Jan 14, 2012
Showing with 35 additions and 1 deletion.
  1. +1 −0 AUTHORS
  2. +31 −0 clint/textui/progress.py
  3. +3 −1 examples/progressbar.py
View
@@ -18,3 +18,4 @@ Patches and Suggestions
- Miguel Araujo <maraujop>
- takluyver
- kracekumar
+- Alejandro Gómez <alejandrogomez>
View
@@ -15,10 +15,12 @@
STREAM = sys.stderr
BAR_TEMPLATE = '%s[%s%s] %i/%i\r'
+MILL_TEMPLATE = '%s %s %i/%i\r'
DOTS_CHAR = '.'
BAR_FILLED_CHAR = '#'
BAR_EMPTY_CHAR = ' '
+MILL_CHARS = ['|', '/', '-', '\\']
def bar(it, label='', width=32, hide=False, empty_char=BAR_EMPTY_CHAR, filled_char=BAR_FILLED_CHAR):
"""Progress iterator. Wrap your iterables with it."""
@@ -65,3 +67,32 @@ def dots(it, label='', hide=False):
STREAM.write('\n')
STREAM.flush()
+
+def mill(it, label='', hide=False,):
+ """Progress iterator. Prints a mill while iterating over the items."""
+
+ def _mill_char(_i):
+ if _i == 100:
+ return ' '
+ else:
+ return MILL_CHARS[_i % len(MILL_CHARS)]
+
+ def _show(_i):
+ if not hide:
+ STREAM.write(MILL_TEMPLATE % (
+ label, _mill_char(_i), _i, count))
+ STREAM.flush()
+
+ count = len(it)
+
+ if count:
+ _show(0)
+
+ for i, item in enumerate(it):
+
+ yield item
+ _show(i+1)
+
+ if not hide:
+ STREAM.write('\n')
+ STREAM.flush()
View
@@ -17,4 +17,6 @@
for i in progress.dots(range(100)):
sleep(random() * 0.2)
-
+
+ for i in progress.mill(range(100)):
+ sleep(random() * 0.2)

0 comments on commit a95e803

Please sign in to comment.