summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cursed.py19
-rw-r--r--main.py38
-rw-r--r--tele.py36
3 files changed, 61 insertions, 32 deletions
diff --git a/cursed.py b/cursed.py
new file mode 100644
index 0000000..754d91a
--- /dev/null
+++ b/cursed.py
@@ -0,0 +1,19 @@
+import curses
+
+
+def start(on_str, on_tab):
+ def main(stdscr):
+ curses.noecho()
+ curses.cbreak()
+ stdscr.keypad(True)
+ string = ""
+ while True:
+ char = stdscr.getkey()
+ if char == '\n':
+ on_str(string)
+ string = ""
+ elif char == '\t':
+ on_tab()
+ else:
+ string += char
+ curses.wrapper(main)
diff --git a/main.py b/main.py
index 8ab18f2..51ab636 100644
--- a/main.py
+++ b/main.py
@@ -1,35 +1,9 @@
-import aioconsole
-import logging
-import telethon
+import cursed
-import credentials
+def on_str(s):
+ print(s)
-logging.basicConfig(
- format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',
- level=logging.WARNING
-)
-client = telethon.TelegramClient(
- "first_test",
- credentials.API_ID,
- credentials.API_HASH
-)
+def on_tab():
+ print("Nu tryckte nån på tab")
-
-@client.on(telethon.events.NewMessage)
-async def new_message(event):
- print(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())
+cursed.start(on_str, on_tab)
diff --git a/tele.py b/tele.py
new file mode 100644
index 0000000..515439f
--- /dev/null
+++ b/tele.py
@@ -0,0 +1,36 @@
+import aioconsole
+import logging
+import telethon
+import curses
+
+import credentials
+
+logging.basicConfig(
+ format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',
+ level=logging.WARNING
+)
+client = telethon.TelegramClient(
+ "first_test",
+ credentials.API_ID,
+ credentials.API_HASH
+)
+
+
+@client.on(telethon.events.NewMessage)
+async def new_message(event):
+ print(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())