Skip to content

Commit

Permalink
Add time
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Aug 20, 2023
1 parent 03ffbe7 commit e7459ba
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions adaptive/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,14 +768,16 @@ def live_info(self, *, update_interval: float = 0.1) -> None:
"""
return live_info(self, update_interval=update_interval)

def live_info_terminal(self, *, update_interval: float = 0.5) -> asyncio.Task:
def live_info_terminal(
self, *, update_interval: float = 0.5, update_same_line: bool = True
) -> asyncio.Task:
async def _update(runner: AsyncRunner) -> None:
try:
while not runner.task.done():
# Clear the terminal
# print("\033[H\033[J", end="")
print("\033[H", end="")
print(_info_text(runner, separator="\t\t"))
if update_same_line:
print("\033[H\033[J", end="")
print(_info_text(runner, separator="\t"))
await asyncio.sleep(update_interval)

except asyncio.CancelledError:
Expand Down Expand Up @@ -879,6 +881,7 @@ def _info_text(runner, separator: str = "\n"):
overhead_color = "\033[31m" # Red

info = [
("time", str(datetime.now())),
("status", f"{color_map[status]}{status}\033[0m"),
("elapsed time", str(timedelta(seconds=runner.elapsed_time()))),
("overhead", f"{overhead_color}{overhead:.2f}%\033[0m"),
Expand All @@ -895,7 +898,7 @@ def _info_text(runner, separator: str = "\n"):

width = 30
formatted_info = [f"{k}: {v}".ljust(width) for i, (k, v) in enumerate(info)]
return "\t".join(formatted_info)
return separator.join(formatted_info)


# Default runner
Expand Down

0 comments on commit e7459ba

Please sign in to comment.