diff --git a/.goxc.json b/.goxc.json index 9ebce0e..e770351 100644 --- a/.goxc.json +++ b/.goxc.json @@ -1,6 +1,7 @@ { "AppName": "gotty-client", "ArtifactsDest": "dist", + "BuildConstraints": "!plan9,!nacl,!solaris", "OutPath": "{{.Dest}}{{.PS}}{{.Version}}{{.PS}}{{.ExeName}}_{{.Version}}_{{.Os}}_{{.Arch}}{{.Ext}}", "TasksExclude": [ "go-test", diff --git a/arch.go b/arch.go new file mode 100644 index 0000000..d856fbd --- /dev/null +++ b/arch.go @@ -0,0 +1,34 @@ +// +build !windows + +package gottyclient + +import ( + "encoding/json" + "fmt" + "os" + "os/signal" + "syscall" + "unsafe" +) + +func notifySignalSIGWINCH(c chan<- os.Signal) { + signal.Notify(c, syscall.SIGWINCH) +} + +func resetSignalSIGWINCH() { + signal.Reset(syscall.SIGWINCH) +} + +func syscallTIOCGWINSZ() ([]byte, error) { + ws := winsize{} + + syscall.Syscall(syscall.SYS_IOCTL, + uintptr(0), uintptr(syscall.TIOCGWINSZ), + uintptr(unsafe.Pointer(&ws))) + + b, err := json.Marshal(ws) + if err != nil { + return nil, fmt.Errorf("json.Marshal error: %v", err) + } + return b, err +} diff --git a/arch_windows.go b/arch_windows.go new file mode 100644 index 0000000..53aaffc --- /dev/null +++ b/arch_windows.go @@ -0,0 +1,16 @@ +package gottyclient + +import ( + "errors" + "os" +) + +func notifySignalSIGWINCH(c chan<- os.Signal) { +} + +func resetSignalSIGWINCH() { +} + +func syscallTIOCGWINSZ() ([]byte, error) { + return nil, errors.New("SIGWINCH isn't supported on this ARCH") +} diff --git a/gotty-client.go b/gotty-client.go index ac67834..cf47e82 100644 --- a/gotty-client.go +++ b/gotty-client.go @@ -9,13 +9,10 @@ import ( "net/http" "net/url" "os" - "os/signal" "regexp" "strings" "sync" - "syscall" "time" - "unsafe" "github.com/moul/gotty-client/vendor/github.com/Sirupsen/logrus" "github.com/moul/gotty-client/vendor/github.com/creack/goselect" @@ -243,23 +240,16 @@ type winsize struct { func (c *Client) termsizeLoop(wg *sync.WaitGroup) { defer wg.Done() ch := make(chan os.Signal, 1) - signal.Notify(ch, syscall.SIGWINCH) - defer signal.Reset(syscall.SIGWINCH) - ws := winsize{} + notifySignalSIGWINCH(ch) + defer resetSignalSIGWINCH() for { - syscall.Syscall(syscall.SYS_IOCTL, - uintptr(0), uintptr(syscall.TIOCGWINSZ), - uintptr(unsafe.Pointer(&ws))) - - b, err := json.Marshal(ws) - if err != nil { - logrus.Warnf("json.Marshal error: %v", err) - } - - err = c.write(append([]byte("2"), b...)) - if err != nil { - logrus.Warnf("ws.WriteMessage failed: %v", err) + if b, err := syscallTIOCGWINSZ(); err != nil { + logrus.Warn(err) + } else { + if err = c.write(append([]byte("2"), b...)); err != nil { + logrus.Warnf("ws.WriteMessage failed: %v", err) + } } select { case <-c.QuitChan: