Skip to content

Commit d69cc17

Browse files
committed
include elapsed in alive_bar handle (fixes #290)
1 parent 817e245 commit d69cc17

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

alive_progress/core/progress.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ def alive_bar(total: Optional[int] = None, *, calibrate: Optional[int] = None, *
114114
unit (str): any text that labels your entities
115115
scale (any): the scaling to apply to units: 'SI', 'IEC', 'SI2'
116116
precision (int): how many decimals do display when scaling
117-
118117
"""
118+
119119
try:
120120
config = config_handler(**options)
121121
except Exception as e:
@@ -341,7 +341,7 @@ def bar_update_hook():
341341

342342
bar_handle = __AliveBarHandle(pause_monitoring, set_title, set_text,
343343
current, lambda: run.monitor_text, lambda: run.rate_text,
344-
lambda: run.eta_text)
344+
lambda: run.eta_text, lambda: run.elapsed)
345345
set_text(), set_title()
346346
start_monitoring()
347347
try:
@@ -391,6 +391,8 @@ def __call__(self):
391391

392392

393393
class _ReadOnlyProperty: # pragma: no cover
394+
"""A read-only descriptor that calls a getter function."""
395+
394396
def __set_name__(self, owner, name):
395397
self.prop = f'_{name}'
396398

@@ -402,13 +404,17 @@ def __set__(self, obj, value):
402404

403405

404406
class _GatedFunction(_ReadOnlyProperty): # pragma: no cover
407+
"""A gated descriptor that calls a getter function, but only if the handle is set."""
408+
405409
def __get__(self, obj, objtype=None):
406410
if obj._handle:
407411
return getattr(obj, self.prop)
408412
return _noop
409413

410414

411415
class _GatedAssignFunction(_GatedFunction): # pragma: no cover
416+
"""A gated descriptor that calls a setter function, but only if the handle is set."""
417+
412418
def __set__(self, obj, value):
413419
self.__get__(obj)(value)
414420

@@ -421,11 +427,14 @@ class __AliveBarHandle:
421427
monitor = _ReadOnlyProperty()
422428
rate = _ReadOnlyProperty()
423429
eta = _ReadOnlyProperty()
430+
elapsed = _ReadOnlyProperty()
424431

425-
def __init__(self, pause, set_title, set_text, get_current, get_monitor, get_rate, get_eta):
432+
def __init__(self, pause, set_title, set_text, get_current, get_monitor, get_rate, get_eta,
433+
get_elapsed):
426434
self._handle, self._pause, self._current = None, pause, get_current
427435
self._title, self._text = set_title, set_text
428436
self._monitor, self._rate, self._eta = get_monitor, get_rate, get_eta
437+
self._elapsed = get_elapsed
429438

430439
# support for disabling the bar() implementation.
431440
def __call__(self, *args, **kwargs):

0 commit comments

Comments
 (0)