mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-28 22:33:59 -06:00
ui/curses: estimate time in progress bars
This commit is contained in:
@@ -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("|"),
|
||||
|
||||
Reference in New Issue
Block a user