summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-03-11 16:32:18 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-03-11 16:32:18 +0100
commitc318b0ba310494f982bbbff7319d8926244684e3 (patch)
tree67cbe466008096db52b863de426055d7e44265d6
parente1b2aa387a4a99351344c10306b65dc29b04fb16 (diff)
downloadtg-c318b0ba310494f982bbbff7319d8926244684e3.tar.gz
move start to console
-rw-r--r--cursed.py33
-rw-r--r--main.py2
2 files changed, 17 insertions, 18 deletions
diff --git a/cursed.py b/cursed.py
index 7e262b5..9ff0bec 100644
--- a/cursed.py
+++ b/cursed.py
@@ -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]
diff --git a/main.py b/main.py
index e317ecc..eb2b3b2 100644
--- a/main.py
+++ b/main.py
@@ -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__":