summaryrefslogtreecommitdiffstats
path: root/cursed.py
diff options
context:
space:
mode:
Diffstat (limited to 'cursed.py')
-rw-r--r--cursed.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/cursed.py b/cursed.py
index 754d91a..905b457 100644
--- a/cursed.py
+++ b/cursed.py
@@ -1,11 +1,25 @@
import curses
+import asyncio
+class Console():
+ def __init__(self, stdscr):
+ self.stdscr = stdscr
-def start(on_str, on_tab):
- def main(stdscr):
+ def __enter__(self):
curses.noecho()
curses.cbreak()
- stdscr.keypad(True)
+ self.stdscr.keypad(True)
+
+ def __exit__(self, _a, _b, _c):
+ curses.nocbreak()
+ self.stdscr.keypad(False)
+ curses.echo()
+ curses.endwin()
+
+
+def start(on_str, on_tab):
+ stdscr = curses.initscr()
+ with Console(stdscr) as _:
string = ""
while True:
char = stdscr.getkey()
@@ -16,4 +30,3 @@ def start(on_str, on_tab):
on_tab()
else:
string += char
- curses.wrapper(main)