Add tty resize api

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2016-02-02 14:31:06 -08:00
parent a42eb9fd63
commit f5fdc548e8

View file

@ -8,6 +8,7 @@ import (
"log"
"net"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
@ -190,11 +191,13 @@ var startCommand = cli.Command{
if err != nil {
fatal(err.Error(), 1)
}
var tty bool
if context.Bool("attach") {
mkterm, err := readTermSetting(bpath)
if err != nil {
fatal(err.Error(), 1)
}
tty = mkterm
if mkterm {
s, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
@ -224,6 +227,18 @@ var startCommand = cli.Command{
}
restoreAndCloseStdin()
}()
if tty {
resize(id, "init", c)
go func() {
s := make(chan os.Signal, 64)
signal.Notify(s, syscall.SIGWINCH)
for range s {
if err := resize(id, "init", c); err != nil {
log.Println(err)
}
}
}()
}
if err := waitForExit(c, id, "init", restoreAndCloseStdin); err != nil {
fatal(err.Error(), 1)
}
@ -231,6 +246,22 @@ var startCommand = cli.Command{
},
}
func resize(id, pid string, c types.APIClient) error {
ws, err := term.GetWinsize(os.Stdin.Fd())
if err != nil {
return err
}
if _, err := c.UpdateProcess(netcontext.Background(), &types.UpdateProcessRequest{
Id: id,
Pid: "init",
Width: uint32(ws.Width),
Height: uint32(ws.Height),
}); err != nil {
return err
}
return nil
}
var (
stdin io.WriteCloser
state *term.State