Skip to content

feat: add support for webassembly - #49

Open
remyleone wants to merge 1 commit into
moby:mainfrom
remyleone:webassembly
Open

feat: add support for webassembly#49
remyleone wants to merge 1 commit into
moby:mainfrom
remyleone:webassembly

Conversation

@remyleone

@remyleoneremyleone commented Aug 21, 2025

Copy link
Copy Markdown

This PR adds support for webassembly in term. I need this patch for compiling kubectl to webassembly kubernetes/kubernetes#133638

Comment threadterm_webassembly.go Outdated
Comment threadterm_webassembly.go Outdated
@remyleone
remyleoneforce-pushed the webassembly branch 3 times, most recently from f840c9c to d41322bCompareAugust 21, 2025 12:30
@jkroepke

Copy link
Copy Markdown

I'm looking forward to this.

Signed-off-by: Rémy Léone <rleone@scaleway.com>
CopilotAI review requested due to automatic review settings June 22, 2026 09:56

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a GOOS=js (WebAssembly via js/wasm) implementation of the term package and adjusts existing Unix build constraints so that Unix-specific code is excluded when building for js.

Changes:

  • Exclude js from Unix/termios implementations via updated build tags.
  • Add a new term_webassembly.go file implementing the platform-specific term functions for GOOS=js.
  • Route term_unix.go and related termios files away from js builds to avoid Unix syscalls on WebAssembly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

FileDescription
termios_unix.goUpdates build tags to exclude js builds from Unix termios implementation.
termios_nonbsd.goUpdates build tags to exclude js builds from non-BSD Unix termios constants.
term_webassembly.goAdds GOOS=js implementation of terminal APIs for WebAssembly builds.
term_unix.goUpdates build tags to exclude js builds from Unix terminal implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadterm_webassembly.go
Comment on lines +28 to +31
func saveState(fd uintptr) (*State, error) {
return &State{}, nil
}

Comment threadterm_webassembly.go
Comment on lines +17 to +22
func getWinsize(fd uintptr) (*Winsize, error) {
window := js.Global().Get("window")
width := uint16(window.Get("innerWidth").Int())
height := uint16(window.Get("innerHeight").Int())
return &Winsize{Width: width, Height: height}, nil
}
Comment threadterm_webassembly.go
Comment on lines +24 to +26
func isTerminal(fd uintptr) bool {
return true
}
Comment threadterm_webassembly.go
Comment on lines +50 to +56
func setWinsize(fd uintptr, ws *Winsize) error {
window := js.Global().Get("window")
window.Set("innerWidth", ws.Width)
window.Set("innerHeight", ws.Height)

return nil
}
Comment threadterm_unix.go
Comment on lines +1 to +2
//go:build !js && !windows
// +build !js,!windows
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@remyleone@jkroepke@thaJeztah@vvoland