pyTermTk: please provide a default nonblocking async input driver
eg based on select.select + os.read ( works fine already with nurses2/batgrl and Textual
for cases where sys.platform in ('emscripten','wasi')
( but not pyodide)
eg typical render task could look like :
import asyncio, select, os
if sys.platform in ("emscripten", "wasi"):
async def main():
# save cursor in case alt screen fails
STDIN = sys.stdin.fileno()
loop = asyncio.get_event_loop()
try:
while not loop.is_closed():
await asyncio.sleep(0) # or 0.016 if not using RequestAnimationFrame
if select.select([STDIN], [], [], 0)[0]:
try:
payload = os.read(STDIN, 1024)
# await handle terminal stream, process events
except OSError:
continue
# save cursor
# render damaged screen zone.
# restore cursor
except asyncio.exceptions.CancelledError:
print("Cancelled")
except KeyboardInterrupt:
print("KeyboardInterrupt")
finally:
pass
# restore term, stop mouse reporting, restore cursor
About this issue
- Original URL
- State: open
- Created 7 months ago
- Comments: 21 (11 by maintainers)
yes, now it works, the network I was using is not very stable. Thanks. I will check this soon, I’ve a busy WE
beware of blocking threads they can lock up browser tabs for good if you ever forget to add a yield on vsync.
python3 -m pip install pygbag name your demo main.py next to the https://github.com/ceccopierangiolieugenio/pyTermTk/tree/main/TermTk folder and you can use
python3 -m pygbag --ume_block 0 main.py
orpython3 -m pygbag --PYBUILD 3.12 --git --ume_block 0 main.py
for more recent and it will package main.py + pyTermTk for the browser and provide a xterm console and then you can go to http://localhost:8000?-i