Skip to content

Commit

Permalink
Small fixes for --watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Bechberger committed Aug 28, 2020
1 parent f1b2984 commit 66ee5fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion temci/run/run_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ def bench(run: int) -> bool:
label=label_format.format(start_label),
file=None if self.pool.run_driver.runs_benchmarks else "-") as runs:
runs.short_limit = 0
every = Settings()["run/watch_every"] + 5
every = Settings()["run/watch_every"]
if Settings()["run/watch"]:
with Screen(scroll=True, keep_first_lines=1) as f:
sys.stdout = f
sys.stderr = f
runs.file = f if self.pool.run_driver.runs_benchmarks else "-"
import click._termui_impl
click._termui_impl.BEFORE_BAR = "\r"
Expand Down
11 changes: 8 additions & 3 deletions temci/utils/curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import threading
import time
from typing import Callable
from typing import Callable, List


class Screen:
Expand Down Expand Up @@ -70,6 +70,7 @@ def isatty(self):
return True

def write(self, text: str):
text = text.replace("\n", "\r\n")
for line in text.splitlines(keepends=True):
first = True
for part in line[0:len(line) - (1 if line.endswith("\n") else 0)].split("\r"):
Expand Down Expand Up @@ -114,14 +115,18 @@ def move_cursor(self, x_offset: int = 0, y_offset: int = 0):
self.x = max(0, self.x + x_offset)
self.y = max(self.keep_first_lines, self.y + y_offset)

def writelines(self, lines: List[str]):
for line in lines:
self.write(line.replace("\n", "\r\n"))

def __exit__(self, exc_type, exc_val, exc_tb):
try:
curses.nocbreak()
self.scr.keypad(0)
self.scr.keypad(False)
curses.echo()
curses.endwin()
os.system('stty sane')
except BaseException as ex:
pass
if self.print_buffer_on_exit:
sys.stdout.writelines([s + "\n" for s in self.buffer])
sys.stdout.writelines([s + "\n" for s in self._shown_buffer])

0 comments on commit 66ee5fe

Please sign in to comment.