Renders completed/total, e.g. '0.5/2.3 G'.
| 19 | |
| 20 | |
| 21 | class FractionColumn(ProgressColumn): |
| 22 | """Renders completed/total, e.g. '0.5/2.3 G'.""" |
| 23 | def __init__(self, unit_scale=False, unit_divisor=1000): |
| 24 | self.unit_scale = unit_scale |
| 25 | self.unit_divisor = unit_divisor |
| 26 | super().__init__() |
| 27 | |
| 28 | def render(self, task): |
| 29 | """Calculate common unit for completed and total.""" |
| 30 | completed = int(task.completed) |
| 31 | total = int(task.total) |
| 32 | if self.unit_scale: |
| 33 | unit, suffix = filesize.pick_unit_and_suffix( |
| 34 | total, |
| 35 | ["", "K", "M", "G", "T", "P", "E", "Z", "Y"], |
| 36 | self.unit_divisor, |
| 37 | ) |
| 38 | else: |
| 39 | unit, suffix = filesize.pick_unit_and_suffix(total, [""], 1) |
| 40 | precision = 0 if unit == 1 else 1 |
| 41 | return Text( |
| 42 | f"{completed/unit:,.{precision}f}/{total/unit:,.{precision}f} {suffix}", |
| 43 | style="progress.download") |
| 44 | |
| 45 | |
| 46 | class RateColumn(ProgressColumn): |