Skip to content

Latest commit

 

History

History
74 lines (51 loc) · 1.41 KB

display.md

File metadata and controls

74 lines (51 loc) · 1.41 KB

Display Package

⏳ Progress

See the progress of an iteration in a simple way

Simple usage

import cereja as cj
import time

my_iterable = ['Cereja', 'is', 'very', 'easy']


for i in cj.Progress.prog(my_iterable):
    print(f"current: {i}")
    time.sleep(2)

# Output on terminal ...

# 🍒 Sys[out] » current: Cereja 
# 🍒 Sys[out] » current: is 
# 🍒 Cereja Progress » [▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▱▱▱▱▱▱▱▱▱▱▱▱▱▱] - 50.00% - 🕢 00:00:02 estimated
Custom Display
import cereja as cj
import time

progress = cj.Progress("My Progress")
print(progress)

print(progress[0])
print(progress[1])
print(progress[2])


class MyCustomState(cj.display.State):
    def display(self, current_value, max_value, *args, **kwargs):
        return f'{current_value} -> {max_value}'

    def done(self, *args, **kwargs):
        return f'FINISHED'


progress[0] = MyCustomState

for i in progress(range(1, 500)):
    time.sleep(1 / i)
With Statement
import cereja as cj
import time

with cj.Progress("My Progress") as prog:
    time.sleep(5)
    for i in prog(range(1, 500)):
        time.sleep(1 / i)
    for i in prog(range(1, 500)):
        time.sleep(1 / i)