Use rich.progress instead of tqdm (#5064)

* Use rich progress instead of tqdm

* Remove tqdm from deps
This commit is contained in:
jack1142
2021-06-03 21:37:53 +02:00
committed by GitHub
parent 0ce2634bb3
commit 8f390147c1
5 changed files with 49 additions and 106 deletions

View File

@@ -13,7 +13,7 @@ import time
from typing import ClassVar, Final, List, Optional, Pattern, Tuple
import aiohttp
from tqdm import tqdm
import rich.progress
from redbot.core import data_manager
from redbot.core.i18n import Translator
@@ -297,22 +297,23 @@ class ServerManager:
fd, path = tempfile.mkstemp()
file = open(fd, "wb")
nbytes = 0
with tqdm(
desc="Lavalink.jar",
total=response.content_length,
file=sys.stdout,
unit="B",
unit_scale=True,
miniters=1,
dynamic_ncols=True,
leave=False,
) as progress_bar:
with rich.progress.Progress(
rich.progress.SpinnerColumn(),
rich.progress.TextColumn("[progress.description]{task.description}"),
rich.progress.BarColumn(),
rich.progress.TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
rich.progress.TimeRemainingColumn(),
rich.progress.TimeElapsedColumn(),
) as progress:
progress_task_id = progress.add_task(
"[red]Downloading Lavalink.jar", total=response.content_length
)
try:
chunk = await response.content.read(1024)
while chunk:
chunk_size = file.write(chunk)
nbytes += chunk_size
progress_bar.update(chunk_size)
progress.update(progress_task_id, advance=chunk_size)
chunk = await response.content.read(1024)
file.flush()
finally: