Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a tty to the runtime #146

Open
rajsite opened this issue Oct 5, 2023 · 5 comments
Open

Expose a tty to the runtime #146

rajsite opened this issue Oct 5, 2023 · 5 comments

Comments

@rajsite
Copy link

rajsite commented Oct 5, 2023

Is there a way to get the equivalent behavior of docker run -it, for example if I wanted to run the docker/doodle containers: https://hub.docker.com/r/docker/doodle/tags

@rajsite
Copy link
Author

rajsite commented Oct 5, 2023

Looks like via the WASI preview 1 layer it wouldn't really be possible today: WebAssembly/WASI#42

What's doable today would be forwarding over telnet / ssh etc: WebAssembly/WASI#161 (comment)

But with WASI preview 2, component model, and wasi-cli there may be early proposals to enable pseudoterminal manipulation: WebAssembly/WASI#161 (comment)

@ktock
Copy link
Owner

ktock commented Oct 6, 2023

@rajsite Tty is available for the applications running in the container. Maybe you need to switch the your terminal to raw mode to get the raw acccess to it (e.g. stty raw -echo ; wasmtime /out/out.wasm vi ; stty -raw echo). But the terminal size is always 80 x 25 as of now because the emulator can't receive SIGWINCH on WASI. Maybe, if needed, we can at least add a flag to allow specifying the terminal size on container startup.

@rajsite
Copy link
Author

rajsite commented Oct 6, 2023

Reason I was thinking a tty isn't available was when running:

./c2w docker/doodle:halloween halloween.wasm
wasmtime halloween.wasm

I get the following error:

panic: exec: "infocmp": executable file not found in $PATH

goroutine 1 [running]:
main.main()
	/project/halloween.go:276 +0xbe8

I get the above error when I forget to pass -it to docker run, i.e. docker run docker/doodle:halloween vs docker run -it docker/doodle:halloween.

So that's where the original phrasing of the question came from. It's assuming there is something else that the -it flag is doing in docker that isn't duplicated in container2wasm for setting up a tty. My guess is that the app is detecting that a tty is not available and trying to use infocomp to query if terminals are available but infocomp isn't in the container (but maybe doesn't need to be if the terminal gets set-up as it expects).

@ktock
Copy link
Owner

ktock commented Oct 7, 2023

@rajsite It seems to lack TERM=xterm envvar which docker seems to add by default and this causes the different behaviour. Could you add it manually when starting the container (e.g. by stty raw -echo ; wasmtime --env TERM=xterm /out/out.wasm ; stty -raw echo)?

@rajsite
Copy link
Author

rajsite commented Oct 9, 2023

Seems to work! So cool!

halloween

Does look like this demo could use a configurable terminal size :P Happy Hal!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants