Textual in WASM? #2764
Replies: 2 comments
-
Someone was experimenting with pyscript late on last year, and someone posted last month that they'd got their app running in pyodide. |
Beta Was this translation helpful? Give feedback.
-
Hi, I have only found a few things that would prevent Textual from running on a python wasm runtime "out of the box" First is that textual.worker.Worker will not enforce thread = False even though The annoying two It may also have some trouble when app code is coming from stdin and not catching OSError here The monkey patch I used to run codebrowser.py on pygbag import asyncio
import select
import os
import textual.events
import textual.driver
import textual.drivers.headless_driver
import textual._xterm_parser
class HeadlessDriver(textual.driver.Driver):
def send_event(self, event: textual.events.Event) -> None:
self._loop.create_task(self._app._post_message(event))
def _get_terminal_size(self) -> tuple[int, int]:
return tuple(map(int, __import__("os").get_terminal_size()))
def write(self, data: str) -> None:
sys.__stdout__.write(data)
def start_application_mode(self) -> None:
loop = asyncio.get_running_loop()
loop.create_task(self.input_handler())
def disable_input(self) -> None:
...
def stop_application_mode(self) -> None:
...
async def input_handler(self):
import sys, os
from platform import window
import textual._xterm_parser
STDIN = sys.stdin.fileno()
def more_data() -> bool:
return select.select([STDIN], [], [], 0)[0]
parser = textual._xterm_parser.XTermParser(more_data, debug=self._debug)
while True:
await asyncio.sleep(0)
if select.select([STDIN], [], [], 0)[0]:
try:
payload = os.read(STDIN, 1024)
if payload:
for event in parser.feed(payload.decode('utf-8')):
self.process_event(event)
except OSError:
continue
textual.drivers.headless_driver.HeadlessDriver = HeadlessDriver There is surely a better way to integrate python wasm but i only spent an hour on this. probably some font width / xterm.js specific problems here with textual-paint |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Will & Team,
What is the current level of Textual functionality in WASM Python? (pyscript or pyodide)
I'd love to be able to use Textual to build 1 single interface for both terminal and web based environments instead of building 1 for terminal interaction and 1 for web based interaction.
Is anyone already using Textual in WASM?
Beta Was this translation helpful? Give feedback.
All reactions