I would like to get the new Python REPL working in the in-browser Emscripten-powered WebAssembly (in Tools/wasm).
I’m not well-versed with terminal emulation, WebAssembly, or Emscripten but I do have an interest in this topic, so I’m starting this discussion with the hope of finding others interested in this niche need within this niche topic.
From my understanding, pyrepl requires a TTY to load properly.
I suspect an xterm.js extension, like xterm-pty, might be required. If anyone would like to work on this or try guiding me in working on this, I would be happy to help.
Sorry to follow up to an old thread here, but I actually spent a little bit of time poking at this yesterday. I made some progress but ultimately wasn’t able to get things working. I’m by no means an expert, but I think getting PyREPL to work with Emscripten is going to be a little tricky.
I did get a build working (kind of) with xterm-pty, which is cool because a lot of the code for managing i/o streams that exists in the current demo is just handled by xterm-pty directly. You can also change some stuff in the build configuration to make it build with readline (which gets rid of an error about a missing rlcompleter module), but the next problem is that, afaict, PyREPL strictly depends on ncurses, and I wasn’t able to figure out how to do an Emscripten build with ncurses. There seem to be some examples of building ncurses for Emscripten (e.g., this repo), but I’m just kind of poking at this stuff for the first time and so not sure how to make that work here.
If anyone has any pointers for how to build Python with curses support for Emscripten, that would be cool. If not, I might try to poke at this some more if I have time, but it’s not currently at the top of my priority list.
In case it’s of use, I put my current progress at: GitHub - adqm/cpython at wasm_repl_pty
There are still a bunch of issues with it, but maybe useful if you want to try to build on it. Here’s a build of the demo from that branch (note that it falls back to the basic REPL and doesn’t know what to do with arrow keys, presumably because of the missing curses library): https://hz.mit.edu/wasm_repl_demo_pty.zip
It also only seems to work in Chromium (not Firefox); I haven’t looked into that yet either.
In the meantime, I did also put in a PR that includes other improvements to the existing WASM REPL; if that’s somehow helpful, feel free to make use of any of that code.
Anyway, sorry to be responding without having an actual solution to your question; but just wanted to share some thoughts since I had been poking at this recently!
I believe that @ambv and @pablogsal noted on the most recent Core.py podcast episode that the ncurses was intended to be removed as a dependency, but never occurred.
Hi! Here’s a reimplementation of the curses bits that _pyrepl needs; put it in the fallback chain in Lib/_pyrepl/curses.py.
It hardcodes values for xterm-256color, which I assume is what you want for xterm.js (i.e. if you did get curses compiled you’d set $TERM to that).
But, now you need to get termios and ioctl working. Both are disabled for Emscripten & WASI.