8000 Remove `console.Terminal` check and use `IsTerminal` from `streams.Out` · docker/compose@f79c281 · GitHub
[go: up one dir, main page]

Skip to content

Commit f79c281

Browse files
vvolandglours
authored andcommitted
Remove console.Terminal check and use IsTerminal from streams.Out
docker/cli v27 changed the return value of `Err()` to `streams.Out` which made the typecheck for `console.File` fail. The check is no longer needed due to the `IsTerminal` method present in `streams.Out` which also has a special handling for Windows console. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent 6a000dc commit f79c281

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
99
github.com/buger/goterm v1.0.4
1010
github.com/compose-spec/compose-go/v2 v2.1.3
11-
github.com/containerd/console v1.0.4
1211
github.com/containerd/containerd v1.7.18
1312
github.com/davecgh/go-spew v1.1.1
1413
github.com/distribution/reference v0.6.0
@@ -81,6 +80,7 @@ require (
8180
github.com/beorn7/perks v1.0.1 // indirect
8281
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
8382
github.com/cespare/xxhash/v2 v2.2.0 // indirect
83+
github.com/containerd/console v1.0.4 // indirect
8484
github.com/containerd/continuity v0.4.3 // indirect
8585
github.com/containerd/errdefs v0.1.0 // indirect
8686
github.com/containerd/log v0.1.0 // indirect

pkg/compose/compose.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"io"
2423
"os"
2524
"strconv"
2625
"strings"
@@ -129,11 +128,11 @@ func (s *composeService) stdin() *streams.In {
129128
return s.dockerCli.In()
130129
}
131130

132-
func (s *composeService) stderr() io.Writer {
131+
func (s *composeService) stderr() *streams.Out {
133132
return s.dockerCli.Err()
134133
}
135134

136-
func (s *composeService) stdinfo() io.Writer {
135+
func (s *composeService) stdinfo() *streams.Out {
137136
if stdioToStdout {
138137
return s.dockerCli.Out()
139138
}

pkg/progress/writer.go

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import (
2121
"io"
2222
"sync"
2323

24-
"github.com/containerd/console"
25-
"github.com/moby/term"
26-
"github.com/sirupsen/logrus"
24+
"github.com/docker/cli/cli/streams"
2725
"golang.org/x/sync/errgroup"
2826

2927
"github.com/docker/compose/v2/pkg/api"
@@ -59,22 +57,22 @@ type progressFunc func(context.Context) error
5957
type progressFuncWithStatus func(context.Context) (string, error)
6058

6159
// Run will run a writer and the progress function in parallel
62-
func Run(ctx context.Context, pf progressFunc, out io.Writer) error {
60+
func Run(ctx context.Context, pf progressFunc, out *streams.Out) error {
6361
_, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) {
6462
return "", pf(ctx)
6563
}, out, "Running")
6664
return err
6765
}
6866

69-
func RunWithTitle(ctx context.Context, pf progressFunc, out io.Writer, progressTitle string) error {
67+
func RunWithTitle(ctx context.Context, pf progressFunc, out *streams.Out, progressTitle string) error {
7068
_, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) {
7169
return "", pf(ctx)
7270
}, out, progressTitle)
7371
return err
7472
}
7573

7674
// RunWithStatus will run a writer and the progress function in parallel and return a status
77-
func RunWithStatus(ctx context.Context, pf progressFuncWithStatus, out io.Writer, progressTitle string) (string, error) {
75+
func RunWithStatus(ctx context.Context, pf progressFuncWithStatus, out *streams.Out, progressTitle string) (string, error) {
7876
eg, _ := errgroup.WithContext(ctx)
7977
w, err := NewWriter(ctx, out, progressTitle)
8078
var result string
@@ -115,25 +113,22 @@ const (
115113
var Mode = ModeAuto
116114

117115
// NewWriter returns a new multi-progress writer
118-
func NewWriter(ctx context.Context, out io.Writer, progressTitle string) (Writer, error) {
119-
_, isTerminal := term.GetFdInfo(out)
116+
func NewWriter(ctx context.Context, out *streams.Out, progressTitle string) (Writer, error) {
117+
isTerminal := out.IsTerminal()
120118
dryRun, ok := ctx.Value(api.DryRunKey{}).(bool)
121119
if !ok {
122120
dryRun = false
123121
}
124122
if Mode == ModeQuiet {
125123
return quiet{}, nil
126124
}
127-
f, isConsole := out.(console.File) // see https://github.com/docker/compose/issues/10560
128-
if Mode == ModeAuto && isTerminal && isConsole {
129-
return newTTYWriter(f, dryRun, progressTitle)
125+
126+
tty := Mode == ModeTTY
127+
if Mode == ModeAuto && isTerminal {
128+
tty = true
130129
}
131-
if Mode == ModeTTY {
132-
if !isConsole {
133-
logrus.Warn("Terminal is not a POSIX console")
134-
} else {
135-
return newTTYWriter(f, dryRun, progressTitle)
136-
}
130+
if tty {
131+
return newTTYWriter(out, dryRun, progressTitle)
137132
}
138133
return &plainWriter{
139134
out: out,
@@ -142,14 +137,9 @@ func NewWriter(ctx context.Context, out io.Writer, progressTitle string) (Writer
142137
}, nil
143138
}
144139

145-
func newTTYWriter(out console.File, dryRun bool, progressTitle string) (Writer, error) {
146-
con, err := console.ConsoleFromFile(out)
147-
if err != nil {
148-
return nil, err
149-
}
150-
140+
func newTTYWriter(out io.Writer, dryRun bool, progressTitle string) (Writer, error) {
151141
return &ttyWriter{
152-
out: con,
142+
out: out,
153143
eventIDs: []string{},
154144
events: map[string]Event{},
155145
repeated: false,

0 commit comments

Comments
 (0)
0