xs/hkexsh/termsize_linux.go

38 lines
833 B
Go
Raw Normal View History

// +build linux
2018-11-23 00:49:09 +00:00
package main
import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
2018-07-05 05:06:07 +00:00
"blitter.com/go/hkexsh/hkexnet"
)
// Handle pty resizes (notify server side)
2018-07-05 05:06:07 +00:00
func handleTermResizes(conn *hkexnet.Conn) {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGWINCH)
wg.Add(1)
2018-11-25 03:40:45 +00:00
// #gv:s/label=\"handleTermResizes\$1\"/label=\"resizeHandler\"/
go func() {
defer wg.Done()
for range ch {
// Query client's term size so we can communicate it to server
// pty after interactive session starts
cols, rows, err := GetSize()
log.Printf("[rows %v cols %v]\n", rows, cols)
if err != nil {
log.Println(err)
}
termSzPacket := fmt.Sprintf("%d %d", rows, cols)
conn.WritePacket([]byte(termSzPacket), hkexnet.CSOTermSize) // nolint: errcheck,gosec
}
}()
ch <- syscall.SIGWINCH // Initial resize.
}