gotty-client/arch.go

34 lines
617 B
Go
Raw Permalink Normal View History

2015-11-19 07:15:13 +08:00
// +build !windows
package gottyclient
import (
"encoding/json"
"fmt"
"golang.org/x/sys/unix"
2015-11-19 07:15:13 +08:00
"os"
"os/signal"
"syscall"
)
func notifySignalSIGWINCH(c chan<- os.Signal) {
signal.Notify(c, syscall.SIGWINCH)
}
func resetSignalSIGWINCH() {
signal.Reset(syscall.SIGWINCH)
}
func syscallTIOCGWINSZ() ([]byte, error) {
2018-04-10 13:51:39 +08:00
ws, err := unix.IoctlGetWinsize(0, unix.TIOCGWINSZ)
if err != nil {
return nil, fmt.Errorf("ioctl error: %v", err)
}
2018-04-10 13:50:09 +08:00
tws := winsize{Rows: ws.Row, Columns: ws.Col}
b, err := json.Marshal(tws)
2015-11-19 07:15:13 +08:00
if err != nil {
return nil, fmt.Errorf("json.Marshal error: %v", err)
}
return b, err
}