Skip to content

Commit ce94452

Browse files
authored
Merge pull request docker#9247 from ndeloof/plain
use plain text progress when ansi=never is set
2 parents a2b9c81 + 57e8e8e commit ce94452

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

cmd/compose/compose.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@ import (
2929
"github.com/compose-spec/compose-go/types"
3030
dockercli "github.com/docker/cli/cli"
3131
"github.com/docker/cli/cli-plugins/manager"
32-
"github.com/docker/compose/v2/cmd/formatter"
33-
"github.com/docker/compose/v2/pkg/utils"
3432
"github.com/morikuni/aec"
3533
"github.com/pkg/errors"
3634
"github.com/sirupsen/logrus"
3735
"github.com/spf13/cobra"
3836
"github.com/spf13/pflag"
3937

38+
"github.com/docker/compose/v2/cmd/formatter"
4039
"github.com/docker/compose/v2/pkg/api"
4140
"github.com/docker/compose/v2/pkg/compose"
41+
"github.com/docker/compose/v2/pkg/progress"
42+
"github.com/docker/compose/v2/pkg/utils"
4243
)
4344

4445
// Command defines a compose CLI command as a func with args
@@ -271,6 +272,12 @@ func RootCommand(backend api.Service) *cobra.Command {
271272
logrus.SetLevel(logrus.TraceLevel)
272273
}
273274
formatter.SetANSIMode(ansi)
275+
switch ansi {
276+
case "never":
277+
progress.Mode = progress.ModePlain
278+
case "tty":
279+
progress.Mode = progress.ModeTTY
280+
}
274281
if opts.WorkDir != "" {
275282
if opts.ProjectDir != "" {
276283
return errors.New(`cannot specify DEPRECATED "--workdir" and "--project-directory". Please use only "--project-directory" instead`)

pkg/progress/writer.go

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,45 @@ func RunWithStatus(ctx context.Context, pf progressFuncWithStatus) (string, erro
9090
return result, err
9191
}
9292

93+
const (
94+
// ModeAuto detect console capabilities
95+
ModeAuto = "auto"
96+
// ModeTTY use terminal capability for advanced rendering
97+
ModeTTY = "tty"
98+
// ModePlain dump raw events to output
99+
ModePlain = "plain"
100+
)
101+
102+
// Mode define how progress should be rendered, either as ModePlain or ModeTTY
103+
var Mode = ModeAuto
104+
93105
// NewWriter returns a new multi-progress writer
94106
func NewWriter(out console.File) (Writer, error) {
95107
_, isTerminal := term.GetFdInfo(out)
96-
97-
if isTerminal {
98-
con, err := console.ConsoleFromFile(out)
99-
if err != nil {
100-
return nil, err
101-
}
102-
103-
return &ttyWriter{
104-
out: con,
105-
eventIDs: []string{},
106-
events: map[string]Event{},
107-
repeated: false,
108-
done: make(chan bool),
109-
mtx: &sync.Mutex{},
110-
}, nil
108+
if Mode == ModeAuto && isTerminal {
109+
return newTTYWriter(out)
110+
}
111+
if Mode == ModeTTY {
112+
return newTTYWriter(out)
111113
}
112-
113114
return &plainWriter{
114115
out: out,
115116
done: make(chan bool),
116117
}, nil
117118
}
119+
120+
func newTTYWriter(out console.File) (Writer, error) {
121+
con, err := console.ConsoleFromFile(out)
122+
if err != nil {
123+
return nil, err
124+
}
125+
126+
return &ttyWriter{
127+
out: con,
128+
eventIDs: []string{},
129+
events: map[string]Event{},
130+
repeated: false,
131+
done: make(chan bool),
132+
mtx: &sync.Mutex{},
133+
}, nil
134+
}

0 commit comments

Comments
 (0)