@@ -135,8 +135,9 @@ def format_meter(n, total, elapsed, ncols=None, prefix='',
135135 rate : float, optional
136136 Manual override for iteration rate.
137137 If [default: None], uses n/elapsed.
138- bar_format : str, optional
138+ bar_format : str or callable , optional
139139 Specify a custom bar string formatting. May impact performance.
140+ Can be a callable that will handle bar display.
140141 [default: '{l_bar}{bar}{r_bar}'], where l_bar is
141142 '{desc}{percentage:3.0f}%|' and r_bar is
142143 '| {n_fmt}/{total_fmt} [{elapsed_str}<{remaining_str}, {rate_fmt}]'
@@ -216,7 +217,10 @@ def format_meter(n, total, elapsed, ncols=None, prefix='',
216217 }
217218
218219 # Interpolate supplied bar format with the dict
219- if '{bar}' in bar_format :
220+ if hasattr (bar_format , '__call__' ):
221+ # Callback user provided function/method to handle display
222+ bar_format (bar_args )
223+ elif '{bar}' in bar_format :
220224 # Format left/right sides of the bar, and format the bar
221225 # later in the remaining space (avoid breaking display)
222226 l_bar_user , r_bar_user = bar_format .split ('{bar}' )
@@ -385,8 +389,9 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True,
385389 Exponential moving average smoothing factor for speed estimates
386390 (ignored in GUI mode). Ranges from 0 (average speed) to 1
387391 (current/instantaneous speed) [default: 0.3].
388- bar_format : str, optional
392+ bar_format : str or callable , optional
389393 Specify a custom bar string formatting. May impact performance.
394+ Can be a callable that will handle bar display.
390395 If unspecified, will use '{l_bar}{bar}{r_bar}', where l_bar is
391396 '{desc}{percentage:3.0f}%|' and r_bar is
392397 '| {n_fmt}/{total_fmt} [{elapsed_str}<{remaining_str}, {rate_fmt}]'
0 commit comments