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
+22
View File
@@ -1,8 +1,30 @@
import datetime
import typing as T
from pqcli import random
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"
def generate_name() -> str:
parts = [
"br|cr|dr|fr|gr|j|kr|l|m|n|pr||||r|sh|tr|v|wh|x|y|z".split("|"),