summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAgnes <agnwe839@student.liu.se>2021-03-06 18:44:58 +0100
committerAgnes <agnwe839@student.liu.se>2021-03-06 18:44:58 +0100
commit75c93c0df3c81fa9bc51bfa8fa00533b13333be6 (patch)
treedc437b5746ee1bdddd7267cfe46530af72103314
parent78fb63fda2f589de118dbe9e073d1c861e81e894 (diff)
downloadtg-75c93c0df3c81fa9bc51bfa8fa00533b13333be6.tar.gz
Curses uses enter and exit
-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)