Skip to content

Commit

Permalink
fixes tty size error
Browse files Browse the repository at this point in the history
Signed-off-by: Lifubang <lifubang@acmcoder.com>

code optimization

Signed-off-by: Lifubang <lifubang@acmcoder.com>

fixes no such exec error when tty resize

Signed-off-by: Lifubang <lifubang@acmcoder.com>
  • Loading branch information
lifubang committed Nov 10, 2018
1 parent 3ea56aa commit 63a773b
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions cli/command/container/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
)

// resizeTtyTo resizes tty to specific height and width
func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id string, height, width uint, isExec bool) {
func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id string, height, width uint, isExec bool) error {
if height == 0 && width == 0 {
return
return nil
}

options := types.ResizeOptions{
Expand All @@ -34,18 +34,35 @@ func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id strin
}

if err != nil {
logrus.Debugf("Error resize: %s", err)
logrus.Debugf("Error resize: %s\r", err)
}
return err
}

// MonitorTtySize updates the container tty size when the terminal tty changes size
func MonitorTtySize(ctx context.Context, cli command.Cli, id string, isExec bool) error {
resizeTty := func() {
resizeTty := func() error {
height, width := cli.Out().GetTtySize()
resizeTtyTo(ctx, cli.Client(), id, height, width, isExec)
return resizeTtyTo(ctx, cli.Client(), id, height, width, isExec)
}

resizeTty()
err := resizeTty()
if err != nil {
retryTimes := 5
retry := 0
go func() {
for {
time.Sleep(10 * time.Millisecond)
err = resizeTty()
if err != nil && retry < retryTimes {
retry++
logrus.Debugf("Resize tty has retried %d times now\r", retry)
continue
}
break
}
}()
}

if runtime.GOOS == "windows" {
go func() {
Expand Down

0 comments on commit 63a773b

Please sign in to comment.