Created
February 5, 2020 23:10
-
-
Save robey/351676cc5a964a7e8dedf34240ab37d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
class ProgressBar: | |
def __init__(self, title: str, width: int): | |
self.title = title | |
self.width = width | |
self.amount = 0 | |
self.update(0) | |
def update(self, amount: int) -> None: | |
"amount is 0 - 100" | |
self.amount = amount | |
fill = round(amount * self.width / 100) | |
self.clear() | |
sys.stdout.write("\r{} [{}{}] {:3d}%\r".format(self.title, "#" * fill, " " * (self.width - fill), amount)) | |
sys.stdout.flush() | |
def clear(self) -> None: | |
sys.stdout.write("\r{}\r".format(" " * (len(self.title) + self.width + 15))) | |
sys.stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment