HandleConsoleResize resizes the console. From https://github.com/containerd/containerd/blob/v1.7.0-rc.2/cmd/ctr/commands/tasks/tasks_unix.go#L43-L68
(ctx context.Context, task resizer, con console.Console)
| 32 | // HandleConsoleResize resizes the console. |
| 33 | // From https://github.com/containerd/containerd/blob/v1.7.0-rc.2/cmd/ctr/commands/tasks/tasks_unix.go#L43-L68 |
| 34 | func HandleConsoleResize(ctx context.Context, task resizer, con console.Console) error { |
| 35 | // do an initial resize of the console |
| 36 | size, err := con.Size() |
| 37 | if err != nil { |
| 38 | return err |
| 39 | } |
| 40 | if err := task.Resize(ctx, uint32(size.Width), uint32(size.Height)); err != nil { |
| 41 | log.G(ctx).WithError(err).Error("resize pty") |
| 42 | } |
| 43 | s := make(chan os.Signal, 16) |
| 44 | signal.Notify(s, unix.SIGWINCH) |
| 45 | go func() { |
| 46 | for range s { |
| 47 | size, err := con.Size() |
| 48 | if err != nil { |
| 49 | log.G(ctx).WithError(err).Error("get pty size") |
| 50 | continue |
| 51 | } |
| 52 | if err := task.Resize(ctx, uint32(size.Width), uint32(size.Height)); err != nil { |
| 53 | log.G(ctx).WithError(err).Error("resize pty") |
| 54 | } |
| 55 | } |
| 56 | }() |
| 57 | return nil |
| 58 | } |