In browser (Chrome / wasm32) terminal emulators

I am aware there are a number of Rust / OpenGL terminal emulators.

The question here is: is there any that can compile to wasm32 and run in Chrome ?

XY problem: I want to run a small terminal emulator in my webapp, and possibly try to run other TUI apps on the (in browser) terminal emulator. [Yes, there will be work that needs to be done to provide a virtual file system; but the focus of this question is just getting a Rust implemented Terminal emulator to run in Chrome/wasm32]

1 Like

Not written in rust, but xterm.js is a pretty popular terminal emulator for in the browser.

I failed to be clear about this in the original post.

  1. The rest of my app is Rust/wasm32, so I really want something in Rust and avoid the mess of wasm_bindgen

  2. I'd also prefer it to be WebGL2 / Webgpu powered rather than DOM powered, for performance reasons.

I just finished implementing Wasmer's JavaScript SDK, which is a Rust crate compiled with wasm-bindgen that lets you run WASI programs in the browser.

Here is the example we made which connects Bash up to an xterm.js terminal:

And here is the deployed app: https://wasmer-examples-wasmer-sh.wasmer.app/

2 Likes

I'm sorry, I don't understand. Is this:

  1. a LOCAL bash using websocket to forward input<->output w/ a terminal running inside a browser

OR

  1. XYZ~ provides a virtual file system (inside the browser), and you are running bash inside the browser, with NO server support

?

It runs everything in the browser using the browser's WebAssembly runtime and Web Workers for multi-threading/multi-processing. The instance will use a temporary in-memory filesystem that the JavaScript caller can mount a Directory to if you want to share files between the JavaScript caller and the WASI instance.

Other than needing to download the sharrattj/bash package from the Wasmer Registry, the demo doesn't require any internet access.

The package itself is just bash compiled with Wasmer's WASIX C toolchain.

2 Likes
  1. This is not what I originally wanted, but this is very interesting.

  2. One thing I want is to run nushell in the browser nushell in browser · Issue #11277 · nushell/nushell · GitHub

  3. Nushell itself is written in Rust. Is there a simpler way to get nushell working ?

It sounds like the main steps are:

  1. compile nushell to wasm -- can I do this via carro build --target=wasm32-unknown-unknown, or do I need some other step ?

  2. I need to link in a virtual file system. Is there a way to do this by adding a pkg to cargo .toml and writing some code, instead of via emscriptsen ?

  3. I need a way to load the wasm from js. This looks similar to the way how JS code typically load Rust compiled wasm32 modujles.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.