Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command/exec: Fill ConsoleSize #3627

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions cli/command/container/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func RunExec(dockerCli command.Cli, options ExecOptions) error {
}
}

fillConsoleSize(execConfig, dockerCli)

response, err := client.ContainerExecCreate(ctx, options.Container, *execConfig)
if err != nil {
return err
Expand All @@ -129,14 +131,22 @@ func RunExec(dockerCli command.Cli, options ExecOptions) error {

if execConfig.Detach {
execStartCheck := types.ExecStartCheck{
Detach: execConfig.Detach,
Tty: execConfig.Tty,
Detach: execConfig.Detach,
Tty: execConfig.Tty,
ConsoleSize: execConfig.ConsoleSize,
}
return client.ContainerExecStart(ctx, execID, execStartCheck)
}
return interactiveExec(ctx, dockerCli, execConfig, execID)
}

func fillConsoleSize(execConfig *types.ExecConfig, dockerCli command.Cli) {
if execConfig.Tty {
height, width := dockerCli.Out().GetTtySize()
execConfig.ConsoleSize = &[2]uint{height, width}
}
}

func interactiveExec(ctx context.Context, dockerCli command.Cli, execConfig *types.ExecConfig, execID string) error {
// Interactive exec requested.
var (
Expand All @@ -157,10 +167,12 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, execConfig *typ
stderr = dockerCli.Err()
}
}
fillConsoleSize(execConfig, dockerCli)

client := dockerCli.Client()
execStartCheck := types.ExecStartCheck{
Tty: execConfig.Tty,
Tty: execConfig.Tty,
ConsoleSize: execConfig.ConsoleSize,
}
resp, err := client.ContainerExecAttach(ctx, execID, execStartCheck)
if err != nil {
Expand Down