From d61433662e548ab2f2318fdd251c92f6259ebc3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 8 Mar 2021 16:31:54 +0100 Subject: refresh on redraw and move redraw to Console --- cursed.py | 17 ++++++++--------- main.py | 5 +---- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/cursed.py b/cursed.py index e63f44f..5259408 100644 --- a/cursed.py +++ b/cursed.py @@ -18,25 +18,24 @@ class Console(): curses.echo() curses.endwin() + def redraw(self, messages): + self.stdscr.clear() + for msg in messages: + self.stdscr.addstr(msg + '\n') + self.stdscr.refresh() + async def start(c, on_str, on_tab, messages): string = "" - redraw(c.stdscr, messages) + c.redraw(messages) while True: char = await asyncio.to_thread(c.stdscr.getkey) if char == '\n' and string != "": await on_str(string) messages.append(string) - redraw(c.stdscr, messages) + c.redraw(messages) string = "" elif char == '\t': await on_tab() else: string += char - - -def redraw(stdscr, messages): - stdscr.clear() - for msg in messages: - stdscr.addstr(msg + '\n') - stdscr.refresh() diff --git a/main.py b/main.py index a65c706..3b40e33 100644 --- a/main.py +++ b/main.py @@ -13,11 +13,8 @@ async def on_tab(): def main(): messages = [] with cursed.Console() as c: - def redraw(messages): - cursed.redraw(c.stdscr, messages) - tele.messages = messages - tele.redraw = redraw + tele.redraw = lambda message: c.redraw(message) with tele.client: tele.client.start() tele.client.loop.run_until_complete(cursed.start(c, on_str, on_tab, messages)) -- cgit v1.2.1