mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
ui/curses: estimate time in progress bars
This commit is contained in:
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user