2018-05-20 21:48:24 +00:00
|
|
|
// +build windows
|
|
|
|
package main
|
|
|
|
|
2018-05-26 20:43:09 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
hkexsh "blitter.com/go/hkexsh"
|
|
|
|
)
|
|
|
|
|
2018-05-20 21:48:24 +00:00
|
|
|
// Handle pty resizes (notify server side)
|
2018-05-26 20:43:09 +00:00
|
|
|
func handleTermResizes(conn *hkexsh.Conn) {
|
|
|
|
var hasStty bool
|
|
|
|
curCols, curRows := 0, 0
|
|
|
|
_, _, err := GetSize()
|
|
|
|
// The above may fail if user doesn't have msys 'stty' util
|
|
|
|
// in PATH. GetSize() will log.Error() once here
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("[1st GetSize:", err, "]")
|
|
|
|
hasStty = false
|
|
|
|
} else {
|
|
|
|
hasStty = true
|
|
|
|
}
|
2018-05-20 21:48:24 +00:00
|
|
|
|
2018-05-26 20:43:09 +00:00
|
|
|
ch := make(chan bool, 1)
|
2018-05-20 21:48:24 +00:00
|
|
|
|
2018-05-26 20:43:09 +00:00
|
|
|
if hasStty {
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
for {
|
|
|
|
ch <- true
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
|
|
|
|
rows := 0
|
|
|
|
cols := 0
|
|
|
|
for range ch {
|
|
|
|
// Query client's term size so we can communicate it to server
|
|
|
|
// pty after interactive session starts
|
|
|
|
cols, rows, err = GetSize()
|
|
|
|
if err == nil {
|
|
|
|
} else {
|
|
|
|
fmt.Println("[GetSize:", err, "]")
|
|
|
|
}
|
|
|
|
if (curRows != rows) || (curCols != curCols) {
|
|
|
|
curRows = rows
|
|
|
|
curCols = cols
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
termSzPacket := fmt.Sprintf("%d %d", curRows, curCols)
|
|
|
|
conn.WritePacket([]byte(termSzPacket), hkexsh.CSOTermSize)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
ch <- true // Initial resize
|
|
|
|
}
|