From 9ac04b24c14d1c0937a2aee5dac9e489d5ef2803 Mon Sep 17 00:00:00 2001 From: Agnes Wendt Date: Sun, 7 Mar 2021 21:42:08 +0100 Subject: wip display messages --- cursed.py | 13 +++++++++++-- main.py | 5 ++++- tele.py | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cursed.py b/cursed.py index 63c3d8f..70d9c7e 100644 --- a/cursed.py +++ b/cursed.py @@ -19,14 +19,23 @@ class Console(): curses.endwin() -async def start(c, on_str, on_tab): +async def start(c, on_str, on_tab, messages): string = "" + redraw(c.stdscr, messages) while True: char = await asyncio.to_thread(c.stdscr.getkey) - if char == '\n': + if char == '\n' and string != "": await on_str(string) + messages.append(string) + redraw(c.stdscr, 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') diff --git a/main.py b/main.py index 27c132e..9763bfa 100644 --- a/main.py +++ b/main.py @@ -11,10 +11,13 @@ async def on_tab(): def main(): + messages = ["hej", "vad", "är", "klockan"] + tele.messages = messages + tele.redraw = cursed.redraw with tele.client: tele.client.start() with cursed.Console() as c: - tele.client.loop.run_until_complete(cursed.start(c, on_str, on_tab)) + tele.client.loop.run_until_complete(cursed.start(c, on_str, on_tab, messages)) if __name__=="__main__": diff --git a/tele.py b/tele.py index b56a692..02ae72f 100644 --- a/tele.py +++ b/tele.py @@ -16,7 +16,8 @@ client = telethon.TelegramClient( @client.on(telethon.events.NewMessage) async def new_message(event): - print(event.raw_text) + messages.append(event.raw_text) + async def send_lines(recipient): -- cgit v1.2.1