Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Parameters
- ``zfill`` bar zero fill symbol (default: -)
- ``decimals`` positive number of decimals in percent complete
(default: 1)
- ``formatter`` a function that formats the count and goal, useful for handling large numbers like file sizes

Any Questions? Report a Bug? Enhancements?
------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ manager.progress_2.stop('stop progress 2')
* `fill` bar fill symbol (default: █)
* `zfill` bar zero fill symbol (default: -)
* `decimals` positive number of decimals in percent complete (default: 1)
* `formatter` a function that formats the count and goal, useful for handling large numbers like file sizes

## Any Questions? Report a Bug? Enhancements?

Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Parameters
- ``zfill`` bar zero fill symbol (default: -)
- ``decimals`` positive number of decimals in percent complete
(default: 1)
- ``formatter`` a function that formats the count and goal, useful for handling large numbers like file sizes

Any Questions? Report a Bug? Enhancements?
------------------------------------------
Expand Down
16 changes: 9 additions & 7 deletions cli_progressbar/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ class Progress:
def __init__(self, goal: int = -1):
self.goal = goal
self.status = ''
self.showing_status = ''
self.longest_status = 0
self.bar_len = 60
self.fill = '█'
self.zfill = '-'
self.decimals = 1
self.formatter = lambda x: x
self.last_len = 0

def set_status(self, status: str):
if status == self.status:
return
self.status = status
self.longest_status = max(len(status), self.longest_status)
self.showing_status = status + ' ' * (self.longest_status - len(status))

def update(self, count: int, status: str = ''):
self.set_status(status)
Expand All @@ -32,9 +30,13 @@ def update(self, count: int, status: str = ''):
percents = round(100.0 * count / float(self.goal), self.decimals)
bar = self.fill * filled_len + self.zfill * (self.bar_len - filled_len)

text = '[%s] %s%s | %s/%s' % (bar, percents, '%', count, self.goal)
if self.showing_status:
text += ' | %s' % self.showing_status
text = '[%s] %s%s | %s/%s' % (bar, percents, '%', self.formatter(count), self.formatter(self.goal))
if self.status:
text += ' | %s' % self.status

padding = ' ' * (self.last_len - len(text))
self.last_len = len(text)
text += padding

pos = getattr(self, 'pos', 0)
self.move_to(pos)
Expand Down