From c001d03aaf41cfcbeae5c4a234e6183f7d719b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 20 May 2022 10:17:36 +0200 Subject: [PATCH] command/exec: Fill ConsoleSize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the exec'd process console dimensions immediately match the users terminal. Signed-off-by: Paweł Gronowski --- cli/command/container/exec.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cli/command/container/exec.go b/cli/command/container/exec.go index 30ce2b1cf56c..23a3813e9790 100644 --- a/cli/command/container/exec.go +++ b/cli/command/container/exec.go @@ -12,6 +12,7 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/opts" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/versions" apiclient "github.com/docker/docker/client" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -117,6 +118,14 @@ func RunExec(dockerCli command.Cli, options ExecOptions) error { } } + if execConfig.Tty { + // ConsoleSize is not supported before API 1.42 + if versions.GreaterThanOrEqualTo(client.ClientVersion(), "1.42") { + height, width := dockerCli.Out().GetTtySize() + execConfig.ConsoleSize = &[2]uint{height, width} + } + } + response, err := client.ContainerExecCreate(ctx, options.Container, *execConfig) if err != nil { return err