emscripten-core / emscripten-core/emscripten
A TTY support by using xterm.js
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
(This is not a bug report, but a feature proposal. I apologize if this is not the right place.)
I have created a prototype that runs several Emscripten'ed CUI programs with xterm.js.
https://xterm-pty.netlify.app/
[xterm-pty](https://github.com/mame/xterm-pty) is an addon for xterm.js to work as a PTY layer. By connecting its "slave" interface of the PTY with the TTY interface of the Emscripten runtime, some real-world CUI programs like VIM works on recent browsers such as Google Chrome and Firefox.
To create this prototype, I had to hook some system calls and events in the Emscripten runtime: ioctl, select, and TTY read/write. Currently, the prototype uses [very dirty hack](https://github.com/mame/xterm-pty/blob/4424b40ad7b5985e217b9aabc74ed3aa3678275b/src/emscriptenHack.ts#L157-L188) to achieve these hooks.
As the hack highly depends on the internal of Emscripten runtime, it is a bit tough to maintain outside of Emscripten project. Is there any chance that Emscripten could import this kind of functionality?
Alternatively, I would appreciate it if Emscripten could provide some necessary Module APIs for the hooks, but the API design might be a bit tricky.
* ioctl syscall accepts a pointer to the heap, and read/write the heap depending on its request type. It's not enough to have a hook that just notifies when ioctl is called.
* select syscall needs to support timeout for real-world CUI programs. We may need to create an API for a polling mechanism.
* I know that there are `Module["stdin"]` and `Module["stdout"]` to hook the stdio, but if we use them, `isatty(0)` returns 0, which is inconvenient. Instead, my prototype [overwrites `TTY.default_tty_ops.get_char` to hook TTY read/write](https://github.com/mame/xterm-pty/blob/4424b40ad7b5985e217b9aabc74ed3aa3678275b/src/emscriptenHack.ts#L151-L153).
If you're not interested in this feature, feel free to close this issue.
Contributor guide
Assessment
This issue has not been assessed yet.