@@ -21,9 +21,7 @@ import (
21
21
"io"
22
22
"sync"
23
23
24
- "github.com/containerd/console"
25
- "github.com/moby/term"
26
- "github.com/sirupsen/logrus"
24
+ "github.com/docker/cli/cli/streams"
27
25
"golang.org/x/sync/errgroup"
28
26
29
27
"github.com/docker/compose/v2/pkg/api"
@@ -59,22 +57,22 @@ type progressFunc func(context.Context) error
59
57
type progressFuncWithStatus func (context.Context ) (string , error )
60
58
61
59
// 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 {
63
61
_ , err := RunWithStatus (ctx , func (ctx context.Context ) (string , error ) {
64
62
return "" , pf (ctx )
65
63
}, out , "Running" )
66
64
return err
67
65
}
68
66
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 {
70
68
_ , err := RunWithStatus (ctx , func (ctx context.Context ) (string , error ) {
71
69
return "" , pf (ctx )
72
70
}, out , progressTitle )
73
71
return err
74
72
}
75
73
76
74
// 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 ) {
78
76
eg , _ := errgroup .WithContext (ctx )
79
77
w , err := NewWriter (ctx , out , progressTitle )
80
78
var result string
@@ -115,25 +113,22 @@ const (
115
113
var Mode = ModeAuto
116
114
117
115
// 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 ( )
120
118
dryRun , ok := ctx .Value (api.DryRunKey {}).(bool )
121
119
if ! ok {
122
120
dryRun = false
123
121
}
124
122
if Mode == ModeQuiet {
125
123
return quiet {}, nil
126
124
}
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
130
129
}
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 )
137
132
}
138
133
return & plainWriter {
139
134
out : out ,
@@ -142,14 +137,9 @@ func NewWriter(ctx context.Context, out io.Writer, progressTitle string) (Writer
142
137
}, nil
143
138
}
144
139
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 ) {
151
141
return & ttyWriter {
152
- out : con ,
142
+ out : out ,
153
143
eventIDs : []string {},
154
144
events : map [string ]Event {},
155
145
repeated : false ,
0 commit comments