initTtySize is to init the TTYs size to the same as the window, if there is an error, it will retry 10 times.
(ctx context.Context, cli command.Cli, id string, isExec bool, resizeTtyFunc func(ctx context.Context, cli command.Cli, id string, isExec bool) error)
| 56 | |
| 57 | // initTtySize is to init the TTYs size to the same as the window, if there is an error, it will retry 10 times. |
| 58 | func initTtySize(ctx context.Context, cli command.Cli, id string, isExec bool, resizeTtyFunc func(ctx context.Context, cli command.Cli, id string, isExec bool) error) { |
| 59 | rTTYfunc := resizeTtyFunc |
| 60 | if rTTYfunc == nil { |
| 61 | rTTYfunc = resizeTty |
| 62 | } |
| 63 | if err := rTTYfunc(ctx, cli, id, isExec); err != nil { |
| 64 | go func() { |
| 65 | var err error |
| 66 | for retry := range 10 { |
| 67 | time.Sleep(time.Duration(retry+1) * 10 * time.Millisecond) |
| 68 | if err = rTTYfunc(ctx, cli, id, isExec); err == nil { |
| 69 | break |
| 70 | } |
| 71 | } |
| 72 | if err != nil { |
| 73 | _, _ = fmt.Fprintln(cli.Err(), "failed to resize tty, using default size") |
| 74 | } |
| 75 | }() |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // MonitorTtySize updates the container tty size when the terminal tty changes size |
| 80 | func MonitorTtySize(ctx context.Context, cli command.Cli, id string, isExec bool) error { |
searching dependent graphs…