-class CursesScreen:
+class TUI:
- def wrap_loop(self, loop):
- curses.wrapper(self.start_loop, loop)
+ def __init__(self):
+ self._log = []
+ curses.wrapper(self.run_loop)
- def safe_addstr(self, y, x, line, attr=0):
+ def addstr(self, y, x, line, attr=0):
if y < self.size.y - 1 or x + len(line) < self.size.x:
self.stdscr.addstr(y, x, line, attr)
else: # workaround to <https://stackoverflow.com/q/7063128>
self.size = self.size - YX(self.size.y % 4, 0)
self.size = self.size - YX(0, self.size.x % 4)
- def start_loop(self, stdscr, loop):
- self.stdscr = stdscr
+ def init_loop(self):
curses.curs_set(0) # hide cursor
- stdscr.timeout(10)
- loop()
+ self.stdscr.timeout(10)
+ self.reset_size()
+
+ def run_loop(self, stdscr):
+ self.stdscr = stdscr
+ self.init_loop()
+ while True:
+ self.loop()
+
+ def log(self, msg):
+ self._log += [msg]