2018-05-20 21:48:24 +00:00
|
|
|
// +build linux
|
2018-11-23 00:49:09 +00:00
|
|
|
|
2018-05-20 21:48:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
2018-07-05 05:06:07 +00:00
|
|
|
"blitter.com/go/hkexsh/hkexnet"
|
2018-05-20 21:48:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Handle pty resizes (notify server side)
|
2018-07-05 05:06:07 +00:00
|
|
|
func handleTermResizes(conn *hkexnet.Conn) {
|
2018-05-20 21:48:24 +00:00
|
|
|
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\"/
|
2018-05-20 21:48:24 +00:00
|
|
|
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
|
2018-05-26 21:11:27 +00:00
|
|
|
cols, rows, err := GetSize()
|
2018-05-20 21:48:24 +00:00
|
|
|
log.Printf("[rows %v cols %v]\n", rows, cols)
|
|
|
|
if err != nil {
|
2018-05-26 20:43:09 +00:00
|
|
|
log.Println(err)
|
2018-05-20 21:48:24 +00:00
|
|
|
}
|
|
|
|
termSzPacket := fmt.Sprintf("%d %d", rows, cols)
|
2018-11-25 18:24:10 +00:00
|
|
|
conn.WritePacket([]byte(termSzPacket), hkexnet.CSOTermSize) // nolint: errcheck,gosec
|
2018-05-20 21:48:24 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
ch <- syscall.SIGWINCH // Initial resize.
|
|
|
|
}
|