emscripten-core / emscripten-core/emscripten

A TTY support by using xterm.js

Aperta
#16,352 12 commenti 3 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C++
Stelle
27.6k
Fork
3.6k
Merge medio
1g 14h
PR unite (30g)
125

Descrizione

(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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia dal prototipo xterm-pty collegato, in particolare dalle righe 151-153 e 157-188 di src/emscriptenHack.ts. Poi esamina i percorsi Emscripten per ioctl, select e la lettura/scrittura di TTY, insieme agli hook stdin/stdout esistenti di Module. Il lavoro è completato quando è disponibile un approccio concordato con un maintainer per esporre la funzionalità PTY o le API Module necessarie.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp, javascript, wasm
Ambito
cli, operating-systems, web-dev
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.