Skip to content

Commit 9349589

Browse files
committed
feat: add support for webassembly
Signed-off-by: Rémy Léone <[email protected]>
1 parent 6c1b69f commit 9349589

File tree

4 files changed

+72
-6
lines changed

4 files changed

+72
-6
lines changed

term_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !windows
2-
// +build !windows
1+
//go:build !js && !windows
2+
// +build !js,!windows
33

44
package term
55

term_webassembly.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//go:build js
2+
// +build js
3+
4+
package term
5+
6+
import "io"
7+
import "os"
8+
import "errors"
9+
10+
// terminalState holds the platform-specific state / console mode for the terminal.
11+
type terminalState struct{}
12+
13+
// GetWinsize returns the window size based on the specified file descriptor.
14+
func getWinsize(fd uintptr) (*Winsize, error) {
15+
return getWinsize(fd)
16+
}
17+
18+
func isTerminal(fd uintptr) bool {
19+
return true
20+
}
21+
22+
func saveState(fd uintptr) (*State, error) {
23+
return &State{}, nil
24+
}
25+
26+
func stdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
27+
return os.Stdin, os.Stdout, os.Stderr
28+
}
29+
30+
func disableEcho(fd uintptr, state *State) error {
31+
return nil
32+
}
33+
34+
func setRawTerminal(fd uintptr) (*State, error) {
35+
return makeRaw(fd)
36+
}
37+
38+
func getFdInfo(in interface{}) (uintptr, bool) {
39+
var inFd uintptr
40+
var isTerminalIn bool
41+
if file, ok := in.(*os.File); ok {
42+
inFd = file.Fd()
43+
isTerminalIn = isTerminal(inFd)
44+
}
45+
return inFd, isTerminalIn
46+
}
47+
48+
func setWinsize(fd uintptr, ws *Winsize) error {
49+
return nil
50+
}
51+
52+
func makeRaw(fd uintptr) (*State, error) {
53+
oldState := State{}
54+
return &oldState, nil
55+
}
56+
57+
func setRawTerminalOutput(fd uintptr) (*State, error) {
58+
return nil, nil
59+
}
60+
61+
func restoreTerminal(fd uintptr, state *State) error {
62+
if state == nil {
63+
return errors.New("invalid terminal state")
64+
}
65+
return nil
66+
}

termios_nonbsd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !darwin && !freebsd && !netbsd && !openbsd && !windows
2-
// +build !darwin,!freebsd,!netbsd,!openbsd,!windows
1+
//go:build !darwin && !freebsd && !netbsd && !openbsd && !js && !windows
2+
// +build !darwin,!freebsd,!netbsd,!openbsd,!js,!windows
33

44
package term
55

termios_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !windows
2-
// +build !windows
1+
//go:build !js && !windows
2+
// +build !js,!windows
33

44
package term
55

0 commit comments

Comments
 (0)