MCPcopy
hub / github.com/Textualize/rich / render

Method render

rich/progress.py:878–911  ·  view source on GitHub ↗

Calculate common unit for completed and total.

(self, task: "Task")

Source from the content-addressed store, hash-verified

876 super().__init__(table_column=table_column)
877
878 def render(self, task: "Task") -> Text:
879 """Calculate common unit for completed and total."""
880 completed = int(task.completed)
881
882 unit_and_suffix_calculation_base = (
883 int(task.total) if task.total is not None else completed
884 )
885 if self.binary_units:
886 unit, suffix = filesize.pick_unit_and_suffix(
887 unit_and_suffix_calculation_base,
888 ["bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"],
889 1024,
890 )
891 else:
892 unit, suffix = filesize.pick_unit_and_suffix(
893 unit_and_suffix_calculation_base,
894 ["bytes", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
895 1000,
896 )
897 precision = 0 if unit == 1 else 1
898
899 completed_ratio = completed / unit
900 completed_str = f"{completed_ratio:,.{precision}f}"
901
902 if task.total is not None:
903 total = int(task.total)
904 total_ratio = total / unit
905 total_str = f"{total_ratio:,.{precision}f}"
906 else:
907 total_str = "?"
908
909 download_status = f"{completed_str}/{total_str} {suffix}"
910 download_text = Text(download_status, style="progress.download")
911 return download_text
912
913
914class TransferSpeedColumn(ProgressColumn):

Calls 1

TextClass · 0.85