From c318b0ba310494f982bbbff7319d8926244684e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 11 Mar 2021 16:32:18 +0100 Subject: move start to console --- cursed.py | 33 ++++++++++++++++----------------- main.py | 2 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/cursed.py b/cursed.py index 7e262b5..9ff0bec 100644 --- a/cursed.py +++ b/cursed.py @@ -28,21 +28,20 @@ class Console(): self.stdscr.addstr(self.typed_message) self.stdscr.refresh() - -async def start(c, on_str, on_tab): - while True: - c.redraw() - char = await asyncio.to_thread(c.stdscr.get_wch) - if isinstance(char, str): - if char == '\n': - if c.typed_message != "": - await on_str(c.typed_message) - c.messages.append(c.typed_message) - c.typed_message = "" - elif char == '\t': - await on_tab() + async def start(self, on_str, on_tab): + while True: + self.redraw() + char = await asyncio.to_thread(self.stdscr.get_wch) + if isinstance(char, str): + if char == '\n': + if self.typed_message != "": + await on_str(self.typed_message) + self.messages.append(self.typed_message) + self.typed_message = "" + elif char == '\t': + await on_tab() + else: + self.typed_message += char else: - c.typed_message += char - else: - if char == 263: - c.typed_message = c.typed_message[:-1] + if char == 263: + self.typed_message = self.typed_message[:-1] diff --git a/main.py b/main.py index e317ecc..eb2b3b2 100644 --- a/main.py +++ b/main.py @@ -17,7 +17,7 @@ def main(): tele.redraw = lambda: c.redraw() with tele.client: tele.client.start() - tele.client.loop.run_until_complete(cursed.start(c, on_str, on_tab)) + tele.client.loop.run_until_complete(c.start(on_str, on_tab)) if __name__=="__main__": -- cgit v1.2.1