diff options
author | Alain Leufroy <alain.leufroy@logilab.fr> | 2012-03-15 13:37:49 +0100 |
---|---|---|
committer | Alain Leufroy <alain.leufroy@logilab.fr> | 2012-03-15 13:37:49 +0100 |
commit | cd55c7901ff556b0593c129536e258554d5165d0 (patch) | |
tree | 7acbe0bc3ec71cea864a38b9720a83aa0dee56b0 /shellutils.py | |
parent | 70683711afccf2d454b81b7903112c8f09f73fcd (diff) | |
download | logilab-common-cd55c7901ff556b0593c129536e258554d5165d0.tar.gz |
[shellutil] add argument to ``ProgressBar.update`` to tune cursor progression (closes #88981)
Diffstat (limited to 'shellutils.py')
-rw-r--r-- | shellutils.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/shellutils.py b/shellutils.py index c713913..749cbac 100644 --- a/shellutils.py +++ b/shellutils.py @@ -315,9 +315,22 @@ class ProgressBar(object): text = property(_get_text, _set_text, _del_text) - def update(self): - """Update the progression bar.""" - self._current += 1 + def update(self, offset=1, exact=False): + """Move FORWARD to new cursor position (cursor will never go backward). + + :offset: fraction of ``size`` + + :exact: + + - False: offset relative to current cursor position if True + - True: offset as an asbsolute position + + """ + if exact: + self._current = offset + else: + self._current += offset + progress = int((float(self._current)/float(self._total))*self._size) if progress > self._progress: self._progress = progress |