From 75c93c0df3c81fa9bc51bfa8fa00533b13333be6 Mon Sep 17 00:00:00 2001 From: Agnes Date: Sat, 6 Mar 2021 18:44:58 +0100 Subject: Curses uses enter and exit --- cursed.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'cursed.py') 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) -- cgit v1.2.1