From b9a0934e74323ef014c6739b63c52c24f19e49c1 Mon Sep 17 00:00:00 2001 From: rr- Date: Tue, 13 Nov 2018 16:06:50 +0100 Subject: [PATCH] ui: show 1d and 1h rather than 1.0d and 1.0h --- pqcli/ui/custom_progress_bar.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pqcli/ui/custom_progress_bar.py b/pqcli/ui/custom_progress_bar.py index eda24da..e125b06 100644 --- a/pqcli/ui/custom_progress_bar.py +++ b/pqcli/ui/custom_progress_bar.py @@ -4,6 +4,13 @@ import typing as T import urwid +def format_float(num: float) -> str: + ret = f"{num:.01f}" + if ret.endswith("0"): + ret = ret[:-2] + return ret + + def format_timespan(timespan: datetime.timedelta) -> str: num = timespan.total_seconds() if num < 60.0: @@ -13,9 +20,9 @@ def format_timespan(timespan: datetime.timedelta) -> str: return f"~{int(num)}m" num /= 60 if num < 24.0: - return f"~{num:.01f}h" + return f"~{format_float(num)}h" num /= 24 - return f"~{num:.01f}d" + return f"~{format_float(num)}d" class CustomProgressBar(urwid.Widget):