One thing that is certainly doable is also to use a standard TUI framework in another language (there are many of them, e.g. https://github.com/magiblot/tvision for C++, https://github.com/charmbracelet/bubbletea for Go, etc.), compile it to WASM, and find how to bridge the WASM output to the browser (I've seen this: https://github.com/cryptool-org/wasm-webterm, but never tried it).
https://github.com/tsl0922/ttyd