|
@@ -0,0 +1,68 @@
|
|
|
|
|
+import curses
|
|
|
|
|
+import io
|
|
|
|
|
+
|
|
|
|
|
+_MAIN_WINDOW = None
|
|
|
|
|
+_INPUT_WINDOW = None
|
|
|
|
|
+_Y_POS = 0
|
|
|
|
|
+_HEIGHT = None
|
|
|
|
|
+_WIDTH = None
|
|
|
|
|
+
|
|
|
|
|
+class StreamWriter(io.TextIOBase):
|
|
|
|
|
+ def write(self, s):
|
|
|
|
|
+ print_str(s)
|
|
|
|
|
+ return len(s)
|
|
|
|
|
+
|
|
|
|
|
+def read_str(prompt='>', echo_to_main_window=True):
|
|
|
|
|
+ _INPUT_WINDOW.addstr(0, 1, prompt)
|
|
|
|
|
+ res = _INPUT_WINDOW.getstr(0, len(prompt) + 2)
|
|
|
|
|
+ _INPUT_WINDOW.clear()
|
|
|
|
|
+ _INPUT_WINDOW.refresh()
|
|
|
|
|
+
|
|
|
|
|
+ if echo_to_main_window:
|
|
|
|
|
+ print_str('%s %s' % (prompt, res))
|
|
|
|
|
+
|
|
|
|
|
+ return res
|
|
|
|
|
+
|
|
|
|
|
+def print_str(s, *args):
|
|
|
|
|
+ global _Y_POS
|
|
|
|
|
+
|
|
|
|
|
+ while _Y_POS >= _HEIGHT:
|
|
|
|
|
+ _MAIN_WINDOW.scroll()
|
|
|
|
|
+ _Y_POS -= 1
|
|
|
|
|
+
|
|
|
|
|
+ _MAIN_WINDOW.addstr(_Y_POS, 0, s)
|
|
|
|
|
+ _MAIN_WINDOW.refresh()
|
|
|
|
|
+ _Y_POS += 1
|
|
|
|
|
+
|
|
|
|
|
+def _run(stdscr, main_method):
|
|
|
|
|
+ curses.echo()
|
|
|
|
|
+ curses.curs_set(0)
|
|
|
|
|
+
|
|
|
|
|
+ height, width = stdscr.getmaxyx()
|
|
|
|
|
+ top_box = stdscr.subwin(height - 3, width, 0, 0)
|
|
|
|
|
+ top_win = top_box.subwin(height - 5, width - 2, 1, 1)
|
|
|
|
|
+ bottom_box = stdscr.subwin(height - 3, 0)
|
|
|
|
|
+ bottom_win = bottom_box.subwin(1, width - 2, height - 2, 1)
|
|
|
|
|
+ top_box.box()
|
|
|
|
|
+ bottom_box.box()
|
|
|
|
|
+
|
|
|
|
|
+ top_win.idlok(True)
|
|
|
|
|
+ top_win.scrollok(True)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ stdscr.refresh()
|
|
|
|
|
+
|
|
|
|
|
+ global _MAIN_WINDOW
|
|
|
|
|
+ _MAIN_WINDOW = top_win
|
|
|
|
|
+
|
|
|
|
|
+ global _INPUT_WINDOW
|
|
|
|
|
+ _INPUT_WINDOW = bottom_win
|
|
|
|
|
+
|
|
|
|
|
+ global _HEIGHT
|
|
|
|
|
+ global _WIDTH
|
|
|
|
|
+ _HEIGHT, _WIDTH = _MAIN_WINDOW.getmaxyx()
|
|
|
|
|
+
|
|
|
|
|
+ main_method()
|
|
|
|
|
+
|
|
|
|
|
+def run(main_method):
|
|
|
|
|
+ curses.wrapper(_run, main_method=main_method)
|