forked from hyperhq/runv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tty.go
40 lines (35 loc) · 886 Bytes
/
tty.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/docker/containerd/api/grpc/types"
"github.com/hyperhq/runv/lib/term"
netcontext "golang.org/x/net/context"
)
func resizeTty(c types.APIClient, container, process string) {
ws, err := term.GetWinsize(os.Stdin.Fd())
if err != nil {
fmt.Printf("Error getting size: %s", err.Error())
return
}
if _, err = c.UpdateProcess(netcontext.Background(), &types.UpdateProcessRequest{
Id: container,
Pid: process,
Width: uint32(ws.Width),
Height: uint32(ws.Height),
}); err != nil {
fmt.Printf("set winsize failed, %v\n", err)
}
}
func monitorTtySize(c types.APIClient, container, process string) {
resizeTty(c, container, process)
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan, syscall.SIGWINCH)
go func() {
for range sigchan {
resizeTty(c, container, process)
}
}()
}