diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-03-11 16:32:18 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-03-11 16:32:18 +0100 |
| commit | c318b0ba310494f982bbbff7319d8926244684e3 (patch) | |
| tree | 67cbe466008096db52b863de426055d7e44265d6 | |
| parent | e1b2aa387a4a99351344c10306b65dc29b04fb16 (diff) | |
| download | tg-c318b0ba310494f982bbbff7319d8926244684e3.tar.gz | |
move start to console
| -rw-r--r-- | cursed.py | 33 | ||||
| -rw-r--r-- | main.py | 2 |
2 files changed, 17 insertions, 18 deletions
@@ -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] @@ -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__": |
