From 786485190e2e9373c707f8baa86fb4292f13b2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 8 Mar 2021 10:02:46 +0100 Subject: refresh scr when receiving messages --- cursed.py | 1 + main.py | 17 ++++++++++------- tele.py | 20 ++------------------ 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/cursed.py b/cursed.py index 70d9c7e..e63f44f 100644 --- a/cursed.py +++ b/cursed.py @@ -39,3 +39,4 @@ 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 9763bfa..a65c706 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ import asyncio import tele async def on_str(s): - await tele.client.send_message("+46703279113", s) + await tele.client.send_message("+46763060644", s) async def on_tab(): @@ -11,12 +11,15 @@ 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: + messages = [] + with cursed.Console() as c: + def redraw(messages): + cursed.redraw(c.stdscr, messages) + + tele.messages = messages + tele.redraw = redraw + with tele.client: + tele.client.start() tele.client.loop.run_until_complete(cursed.start(c, on_str, on_tab, messages)) diff --git a/tele.py b/tele.py index 02ae72f..2dc3562 100644 --- a/tele.py +++ b/tele.py @@ -2,6 +2,7 @@ import aioconsole import logging import telethon import credentials +import cursed logging.basicConfig( format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s', @@ -13,24 +14,7 @@ client = telethon.TelegramClient( credentials.API_HASH ) - @client.on(telethon.events.NewMessage) async def new_message(event): messages.append(event.raw_text) - - - -async def send_lines(recipient): - while True: - line = await aioconsole.ainput() - await client.send_message(recipient, line) - - -async def main(): - await send_lines(recipient=input("Phone number to chat with: ")) - -''' -with client: - client.start() - client.loop.run_until_complete(main()) -''' + redraw(messages) -- cgit v1.2.1