summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAgnes <agnwe839@student.liu.se>2021-03-06 22:12:01 +0100
committerAgnes <agnwe839@student.liu.se>2021-03-06 22:12:01 +0100
commit9a742a6bcbc4df9af0ed576fc2b457f58fd5e590 (patch)
tree27a693f2b6a58e9c320148a0144ecf592d1bca66
parent31dd18fd973947adf21eb129955e33599b6617c4 (diff)
downloadtg-9a742a6bcbc4df9af0ed576fc2b457f58fd5e590.tar.gz
wip
-rw-r--r--cursed.py33
-rw-r--r--main.py11
2 files changed, 27 insertions, 17 deletions
diff --git a/cursed.py b/cursed.py
index e07ea05..d275141 100644
--- a/cursed.py
+++ b/cursed.py
@@ -3,32 +3,33 @@ import asyncio
import sys
class Console():
- def __init__(self, stdscr):
- self.stdscr = stdscr
+ def __init__(self):
+ self.stdscr = curses.initscr()
def __enter__(self):
print("ENTER")
curses.noecho()
curses.cbreak()
self.stdscr.keypad(True)
+ print("Enter färdig")
- def __exit__(self, _a, _b, _c):
+ def __exit__(self, *_):
+ print("EXIT")
curses.nocbreak()
self.stdscr.keypad(False)
curses.echo()
curses.endwin()
-async def start(on_str, on_tab):
- stdscr = curses.initscr()
- with Console(stdscr) as _:
- string = ""
- while True:
- char = await asyncio.to_thread(stdscr.getkey)
- if char == '\n':
- await on_str(string)
- string = ""
- elif char == '\t':
- await on_tab()
- else:
- string += char
+async def start(c, on_str, on_tab):
+ print("start")
+ string = ""
+ while True:
+ char = await asyncio.to_thread(c.stdscr.getkey)
+ if char == '\n':
+ await on_str(string)
+ string = ""
+ elif char == '\t':
+ await on_tab()
+ else:
+ string += char
diff --git a/main.py b/main.py
index 5336d05..d89f93e 100644
--- a/main.py
+++ b/main.py
@@ -9,4 +9,13 @@ async def on_tab():
print("tab")
-asyncio.new_event_loop().run_until_complete(cursed.start(on_str, on_tab))
+def main():
+ print("hejhej")
+ with cursed.Console() as c:
+ print("hej")
+ print(c)
+ asyncio.new_event_loop().run_until_complete(cursed.start(c, on_str, on_tab))
+
+
+if __name__=="__main__":
+ main()