sjmikler / progress-table

Display progress as a pretty table in the command line.
MIT License
98 stars 3 forks source link

[FEATURE] Handling progress bars as objects #11

Closed sjmikler closed 8 months ago

sjmikler commented 8 months ago

It would be nice to be able to treat progress bars as objects and update them manually.

This is available in tqdm:

pbar = tqdm(total=100)
for i in range(10):
    sleep(0.1)
    pbar.update(10)
pbar.close()

The suggestion is to have the equivalent in progress-table:

pbar = table.pbar(total=100)
for i in range(10):
    sleep(0.1)
    pbar.update(10)
pbar.close()
sjmikler commented 8 months ago

This feature was added in version 1.2:

import time
import random
from progress_table import ProgressTableV1

table = ProgressTableV1()

total = 0
target = 1000
pbar = table.pbar(1000)

while total < target:
    new_value = random.randint(0, 100)
    total += new_value

    table["random int"] = new_value
    table["random float"] = random.random()
    table["current total"] = total

    pbar.update(new_value)
    table.next_row()
    time.sleep(0.1)
table.close()