You can create multicolored progress bars to track different categories within a single bar. Colors are drawn from right to left in the order subcounters are added.
When using multicolored progress bars, the following additional fields are available for bar_format:
count_n (int): Current value of count for the $n$-th subcounter.count_0 (int): Remaining count after deducting counts for all subcounters.count_00 (int): Sum of counts from all subcounters.percentage_n (float): Percentage complete for the $n$-th subcounter.percentage_0 (float): Remaining percentage after deducting percentages for all subcounters.percentage_00 (float): Total of percentages from all subcounters.
If you call Counter.add_subcounter_ with all_fields=True, the subcounter also provides:
eta_n (str): Estimated time to completion for the $n$-th subcounter.rate_n (float): Average increments per second since the parent was created for the $n$-th subcounter.
import random
import time
import enlighten
# Example: Tracking test results (Success, Failures, Errors)
bar_format = u'{desc}{desc_pad}{percentage:3.0f}%|{bar}| ' + \
u'S:{count_0:{len_total}d} ' + \
u'F:{count_2:{len_total}d} ' + \
u'E:{count_1:{len_total}d} ' + \
u'[{elapsed}<{eta}, {rate:.2f}{unit_pad}{unit}/s]'
manager = enlighten.get_manager()
success = manager.counter(total=100, desc='Testing', unit='tests',
color='green', bar_format=bar_format)
errors = success.add_subcounter('white')
failures = success.add_subcounter('red')
while success.count < 100:
time.sleep(random.uniform(0.1, 0.3))
result = random.randint(0, 10)
if result == 7:
errors.update()
elif result in (5, 6):
failures.update()
else:
success.update()