Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions term_unix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !windows
// +build !windows
//go:build !js && !windows
// +build !js,!windows

package term

Expand Down
76 changes: 76 additions & 0 deletions term_webassembly.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//go:build js
// +build js

package term

import (
"errors"
"io"
"os"
"syscall/js"
)

// terminalState holds the platform-specific state / console mode for the terminal.
type terminalState struct{}

// GetWinsize returns the window size based on the specified file descriptor.
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
}

func isTerminal(fd uintptr) bool {
return true
}

func saveState(fd uintptr) (*State, error) {
return &State{}, nil
}

func stdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
return os.Stdin, os.Stdout, os.Stderr
}

func disableEcho(fd uintptr, state *State) error {
return nil
}
Comment on lines +36 to +38
Copy link
Member

Choose a reason for hiding this comment

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

This seems rather dangerous, or at least it means that it will compile, but silently discard setting this option and (e.g.) print passwords?

Wondering if it should either error, or if we need to make it a compile option when trying to use these parts with webassembly (i.e., don't have these functions implemented).

cc @AkihiroSuda @vvoland any thoughts?

Copy link

Choose a reason for hiding this comment

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

Yeah not sure about that either.

Does k8s end up using them somehow?
If not, perhaps it would be better to omit these functions on wasm (so their usage wouldn't compile)?

Copy link
Author

Choose a reason for hiding this comment

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


func setRawTerminal(fd uintptr) (*State, error) {
return makeRaw(fd)
}

func getFdInfo(in interface{}) (uintptr, bool) {
var inFd uintptr
var isTerminalIn bool
if file, ok := in.(*os.File); ok {
inFd = file.Fd()
isTerminalIn = isTerminal(inFd)
}
return inFd, isTerminalIn
}

func setWinsize(fd uintptr, ws *Winsize) error {
window := js.Global().Get("window")
window.Set("innerWidth", ws.Width)
window.Set("innerHeight", ws.Height)

return nil
}

func makeRaw(fd uintptr) (*State, error) {
oldState := State{}
return &oldState, nil
}

func setRawTerminalOutput(fd uintptr) (*State, error) {
return nil, nil
}

func restoreTerminal(fd uintptr, state *State) error {
if state == nil {
return errors.New("invalid terminal state")
}
return nil
}
4 changes: 2 additions & 2 deletions termios_nonbsd.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !darwin && !freebsd && !netbsd && !openbsd && !windows
// +build !darwin,!freebsd,!netbsd,!openbsd,!windows
//go:build !darwin && !freebsd && !netbsd && !openbsd && !js && !windows
// +build !darwin,!freebsd,!netbsd,!openbsd,!js,!windows

package term

Expand Down
4 changes: 2 additions & 2 deletions termios_unix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !windows
// +build !windows
//go:build !js && !windows
// +build !js,!windows

package term

Expand Down