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" "log"
"net" "net"
"os" "os"
"os/signal"
"path/filepath" "path/filepath"
"strings" "strings"
"syscall" "syscall"
@ -190,11 +191,13 @@ var startCommand = cli.Command{
if err != nil { if err != nil {
fatal(err.Error(), 1) fatal(err.Error(), 1)
} }
var tty bool
if context.Bool("attach") { if context.Bool("attach") {
mkterm, err := readTermSetting(bpath) mkterm, err := readTermSetting(bpath)
if err != nil { if err != nil {
fatal(err.Error(), 1) fatal(err.Error(), 1)
} }
tty = mkterm
if mkterm { if mkterm {
s, err := term.SetRawTerminal(os.Stdin.Fd()) s, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil { if err != nil {
@ -224,6 +227,18 @@ var startCommand = cli.Command{
} }
restoreAndCloseStdin() 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 { if err := waitForExit(c, id, "init", restoreAndCloseStdin); err != nil {
fatal(err.Error(), 1) 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 ( var (
stdin io.WriteCloser stdin io.WriteCloser
state *term.State state *term.State