Rockhopper-Technologies / enlighten

Enlighten Progress Bar for Python Console Apps
https://python-enlighten.readthedocs.io
Mozilla Public License 2.0
416 stars 25 forks source link

Show status of variable while updating the progress var #22

Closed jiwidi closed 4 years ago

jiwidi commented 4 years ago

Describe the solution you'd like Hi! I would like to use the library to also display the last value of a variable on each loop execution.

Lets say for example:

import time
import enlighten

pbar = enlighten.Counter(total=100, desc='Basic', unit='ticks')
i=0
for num in range(100):
    i+=1
    time.sleep(0.1)  # Simulate work
    pbar.update()

Is there anyway to display the value of i (being changed on every iteration) on the progress bar?

avylove commented 4 years ago

You're in luck, that feature was added recently.

import time
import enlighten

bar_format = u'{desc}{desc_pad} i:{i} {percentage:3.0f}%|{bar}| {count:{len_total}d}/{total:d} ' + \
             u'[{elapsed}<{eta}, {rate:.2f}{unit_pad}{unit}/s]'

my_fields = {'i': 0}
pbar = enlighten.Counter(total=100, desc='Basic', unit='ticks',
                         bar_format=bar_format, additional_fields=my_fields)

for num in range(100):
    my_fields['i'] += 1
    time.sleep(0.1)  # Simulate work
    pbar.update()

It might also be good to add an example of this in the docs.

avylove commented 4 years ago

I actually reworked this a bit in the last release and now you can specify additional user-defined fields as keywords. It's described here.