diff options
| author | Agnes <agnwe839@student.liu.se> | 2021-03-06 18:44:58 +0100 |
|---|---|---|
| committer | Agnes <agnwe839@student.liu.se> | 2021-03-06 18:44:58 +0100 |
| commit | 75c93c0df3c81fa9bc51bfa8fa00533b13333be6 (patch) | |
| tree | dc437b5746ee1bdddd7267cfe46530af72103314 | |
| parent | 78fb63fda2f589de118dbe9e073d1c861e81e894 (diff) | |
| download | tg-75c93c0df3c81fa9bc51bfa8fa00533b13333be6.tar.gz | |
Curses uses enter and exit
| -rw-r--r-- | cursed.py | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -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) |
