diff options
| author | Agnes <agnwe839@student.liu.se> | 2021-03-06 21:53:04 +0100 |
|---|---|---|
| committer | Agnes <agnwe839@student.liu.se> | 2021-03-06 21:53:04 +0100 |
| commit | 31dd18fd973947adf21eb129955e33599b6617c4 (patch) | |
| tree | 3462311ca5aa8fc933e846f178c93b560d1d9082 | |
| parent | 75c93c0df3c81fa9bc51bfa8fa00533b13333be6 (diff) | |
| download | tg-31dd18fd973947adf21eb129955e33599b6617c4.tar.gz | |
Make curses async
| -rw-r--r-- | cursed.py | 10 | ||||
| -rw-r--r-- | main.py | 11 |
2 files changed, 13 insertions, 8 deletions
@@ -1,11 +1,13 @@ import curses import asyncio +import sys class Console(): def __init__(self, stdscr): self.stdscr = stdscr def __enter__(self): + print("ENTER") curses.noecho() curses.cbreak() self.stdscr.keypad(True) @@ -17,16 +19,16 @@ class Console(): curses.endwin() -def start(on_str, on_tab): +async def start(on_str, on_tab): stdscr = curses.initscr() with Console(stdscr) as _: string = "" while True: - char = stdscr.getkey() + char = await asyncio.to_thread(stdscr.getkey) if char == '\n': - on_str(string) + await on_str(string) string = "" elif char == '\t': - on_tab() + await on_tab() else: string += char @@ -1,9 +1,12 @@ import cursed +import asyncio -def on_str(s): +async def on_str(s): print(s) -def on_tab(): - print("Nu tryckte nån på tab") -cursed.start(on_str, on_tab) +async def on_tab(): + print("tab") + + +asyncio.new_event_loop().run_until_complete(cursed.start(on_str, on_tab)) |
