ui/curses: estimate time in progress bars

This commit is contained in:
rr-
2019-01-04 16:40:30 +01:00
parent b20c4b4b34
commit 0133802570
9 changed files with 107 additions and 35 deletions
+2 -21
View File
@@ -3,26 +3,7 @@ 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:
return f"~{int(num)}s"
num /= 60
if num < 60.0:
return f"~{int(num)}m"
num /= 60
if num < 24.0:
return f"~{format_float(num)}h"
num /= 24
return f"~{format_float(num)}d"
from pqcli.lingo import format_timespan
class CustomProgressBar(urwid.Widget):
@@ -37,7 +18,7 @@ class CustomProgressBar(urwid.Widget):
self.normal = "progressbar-normal"
self.complete = "progressbar-done"
self.smooth = "progressbar-smooth"
self.last_tick: T.Optional[datetime.datetime, float] = None
self.last_tick: T.Optional[T.Tuple[datetime.datetime, float]] = None
@property
def time_left(self) -> T.Optional[datetime.timedelta]: