Skip to content

Commit

Permalink
print progress bar all on one line
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt committed Apr 30, 2017
1 parent e3b8c77 commit f61891e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

Version 2.11.0
================
- Use only 1 line to print the progress bar (instead of the previous too lines)


Version 2.10.0
================
- Fixes an issue with Jupyter Notebook 4.3.1 when the `ETA` got printed on new lines
Expand Down
2 changes: 1 addition & 1 deletion pyprind/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
from .generator_factory import prog_bar


__version__ = '2.10.0'
__version__ = '2.11.0'
8 changes: 2 additions & 6 deletions pyprind/progbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def __init__(self, iterations, track_time=True, width=30, bar_char='#',
self._adjust_width()
self.bar_char = bar_char
self.last_progress = 0
self._print_labels()

if monitor:
try:
Expand All @@ -71,16 +70,13 @@ def _adjust_width(self):
# reported that self.max_iter was converted to
# float. Thus this fix to prevent float multiplication of chars.

def _print_labels(self):
self._stream_out('0% {} 100%\n'.format(' ' * (self.bar_width - 6)))
self._stream_flush()

def _cache_progress_bar(self, progress):
remaining = self.bar_width - progress
self._cached_output += '[{}{}]'.format(self.bar_char * int(progress),
self._cached_output += '0% [{}{}] 100%'.format(self.bar_char * int(progress),
' ' * int(remaining))

def _print(self, force_flush=False):
self._stream_flush()
progress = floor(self._calc_percent() / 100 * self.bar_width)
if self.update_interval:
do_update = time.time() - self.last_time >= self.update_interval
Expand Down
1 change: 1 addition & 0 deletions pyprind/progpercent.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def _cache_percent_indicator(self, last_progress):

def _print(self, force_flush=False):
""" Prints formatted percentage and tracked time to the screen."""
self._stream_flush()
next_perc = self._calc_percent()
if self.update_interval:
do_update = time.time() - self.last_time >= self.update_interval
Expand Down

0 comments on commit f61891e

Please sign in to comment.