frobar: Fix bytes sizes

This commit is contained in:
Geoffrey Frogeye 2024-06-24 00:34:42 +02:00
parent 8edb670486
commit 91df3670f6
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8

View file

@ -30,18 +30,19 @@ log = logging.getLogger()
# PulseaudioProvider and MpdProvider)
def humanSize(num: int) -> str:
def humanSize(numi: int) -> str:
"""
Returns a string of width 3+3
"""
num = float(numi)
for unit in ("B ", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"):
if abs(num) < 1000:
if num >= 10:
return "{:3d}{}".format(int(num), unit)
else:
return "{:.1f}{}".format(num, unit)
num //= 1024
return "{:d}YiB".format(num)
num /= 1024
return "{:d}YiB".format(numi)
def randomColor(seed: int | bytes = 0) -> str: