def render(self, task): """Calculate common unit for completed and total.""" completed = int(task.completed) total = int(task.total) if self.unit_scale: unit, suffix = filesize.pick_unit_and_suffix( total, ["", "K", "M", "G", "T", "P", "E", "Z", "Y"], self.unit_divisor, ) else: unit, suffix = filesize.pick_unit_and_suffix(total, [""], 1) precision = 0 if unit == 1 else 1 return Text( f"{completed/unit:,.{precision}f}/{total/unit:,.{precision}f} {suffix}", style="progress.download")
def render(self, task): """Show data transfer speed.""" speed = task.speed if speed is None: return Text(f"? {self.unit}/s", style="progress.data.speed") if self.unit_scale: unit, suffix = filesize.pick_unit_and_suffix( speed, ["", "K", "M", "G", "T", "P", "E", "Z", "Y"], self.unit_divisor, ) else: unit, suffix = filesize.pick_unit_and_suffix(speed, [""], 1) precision = 0 if unit == 1 else 1 return Text(f"{speed/unit:,.{precision}f} {suffix}{self.unit}/s", style="progress.data.speed")
def render(task): """Calculate common unit for completed and total.""" completed = int(task.completed) total = int(task.total) unit, suffix = filesize.pick_unit_and_suffix( total, ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], 1024) completed_ratio = completed / unit total_ratio = total / unit precision = 0 if unit == 1 else 1 completed_str = f"{completed_ratio:,.{precision}f}" total_str = f"{total_ratio:,.{precision}f}" download_status = f"{completed_str}/{total_str} {suffix}" download_text = Text(download_status, style="[bright_white]") return download_text